-
Notifications
You must be signed in to change notification settings - Fork 849
Fix #1021 by updating View constructor to convert state as dict to class object #1022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,8 @@ def __init__( | |
| self.blocks = Block.parse_all(blocks) | ||
| self.private_metadata = private_metadata | ||
| self.state = state | ||
| if self.state is not None and isinstance(self.state, dict): | ||
| self.state = ViewState(**self.state) | ||
| self.hash = hash | ||
| self.clear_on_close = clear_on_close | ||
| self.notify_on_close = notify_on_close | ||
|
|
@@ -155,29 +157,30 @@ def __init__( | |
| ): | ||
| value_objects: Dict[str, Dict[str, ViewStateValue]] = {} | ||
| new_state_values = copy.copy(values) | ||
| for block_id, actions in new_state_values.items(): | ||
| if actions is None: # skipcq: PYL-R1724 | ||
| continue | ||
| elif isinstance(actions, dict): | ||
| new_actions = copy.copy(actions) | ||
| for action_id, v in actions.items(): | ||
| if isinstance(v, dict): | ||
| d = copy.copy(v) | ||
| value_object = ViewStateValue(**d) | ||
| elif isinstance(v, ViewStateValue): | ||
| value_object = v | ||
| else: | ||
| self._show_warning_about_unknown(v) | ||
| continue | ||
| new_actions[action_id] = value_object | ||
| value_objects[block_id] = new_actions | ||
| else: | ||
| self._show_warning_about_unknown(v) | ||
| if isinstance(new_state_values, dict): # just in case | ||
| for block_id, actions in new_state_values.items(): | ||
| if actions is None: # skipcq: PYL-R1724 | ||
| continue | ||
| elif isinstance(actions, dict): | ||
| new_actions = copy.copy(actions) | ||
| for action_id, v in actions.items(): | ||
| if isinstance(v, dict): | ||
| d = copy.copy(v) | ||
| value_object = ViewStateValue(**d) | ||
| elif isinstance(v, ViewStateValue): | ||
| value_object = v | ||
| else: | ||
| self._show_warning_about_unknown(v) | ||
| continue | ||
| new_actions[action_id] = value_object | ||
| value_objects[block_id] = new_actions | ||
| else: | ||
| self._show_warning_about_unknown(v) | ||
| self.values = value_objects | ||
|
|
||
| def to_dict(self, *args) -> Dict[str, Dict[str, Dict[str, dict]]]: # type: ignore | ||
| self.validate_json() | ||
| if self.values: # skipcq: PYL-R1705 | ||
| if self.values is not None: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been a potential bug - |
||
| dict_values: Dict[str, Dict[str, dict]] = {} | ||
| for block_id, actions in self.values.items(): | ||
| if actions: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ | |
| "callback_id": "view_4", | ||
| "external_id": "some-unique-id", | ||
| "state": { | ||
| "values": [] | ||
| "values": {} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been a potential issue of test data. The |
||
| }, | ||
| "hash": "1569362015.55b5e41b", | ||
| "clear_on_close": true, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ def setUp(self) -> None: | |
| def verify_loaded_view_object(self, file): | ||
| input = json.load(file) | ||
| view = View(**input) | ||
| self.assertTrue(view.state is None or isinstance(view.state, ViewState)) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion used to be failing before the change. Before the change in this PR, the passing one is |
||
| self.assertDictEqual(input, view.to_dict()) | ||
|
|
||
| # -------------------------------- | ||
|
|
@@ -110,6 +111,18 @@ def test_valid_construction(self): | |
| ), | ||
| ), | ||
| ], | ||
| state=ViewState( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just in case, added test pattern to pass a |
||
| values={ | ||
| "b1": { | ||
| "a1": ViewStateValue(type="plain_text_input", value="Title") | ||
| }, | ||
| "b2": { | ||
| "a2": ViewStateValue( | ||
| type="plain_text_input", value="Description" | ||
| ) | ||
| }, | ||
| } | ||
| ), | ||
| ) | ||
| modal_view.validate_json() | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we no longer use the code analyzer, we can remove this type of comment.