Skip to content

Commit

Permalink
fix keyerror if no state in window_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
abrichr committed Jul 21, 2024
1 parent 9de2f02 commit 001c8fa
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions openadapt/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,27 +553,31 @@ def to_prompt_dict(self, include_data: bool = True) -> dict[str, Any]:
# and not isinstance(getattr(models.WindowEvent, key), property)
}
)
if include_data:
key_suffixes = ["value", "h", "w", "x", "y", "description", "title", "help"]
if sys.platform == "win32":
logger.warning(
"key_suffixes have not yet been defined on Windows."
"You can help by uncommenting the lines below and pasting "
"the contents of the window_dict into a new GitHub Issue."
)
# from pprint import pformat
# logger.info(f"window_dict=\n{pformat(window_dict)}")
# import ipdb; ipdb.set_trace()
window_state = window_dict["state"]
window_state["data"] = utils.clean_dict(
utils.filter_keys(
window_state["data"],
key_suffixes,
)
)
else:
window_dict["state"].pop("data")
window_dict["state"].pop("meta")
if "state" in window_dict:
if include_data:
key_suffixes = [
"value", "h", "w", "x", "y", "description", "title", "help",
]
if sys.platform == "win32":
logger.warning(
"key_suffixes have not yet been defined on Windows."
"You can help by uncommenting the lines below and pasting "
"the contents of the window_dict into a new GitHub Issue."
)
# from pprint import pformat
# logger.info(f"window_dict=\n{pformat(window_dict)}")
# import ipdb; ipdb.set_trace()
if "state" in window_dict:
window_state = window_dict["state"]
window_state["data"] = utils.clean_dict(
utils.filter_keys(
window_state["data"],
key_suffixes,
)
)
else:
window_dict["state"].pop("data")
window_dict["state"].pop("meta")
return window_dict


Expand Down

0 comments on commit 001c8fa

Please sign in to comment.