Skip to content
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

Fix #1021 by updating View constructor to convert state as dict to class object #1022

Merged
merged 1 commit into from May 27, 2021

Conversation

seratch
Copy link
Member

@seratch seratch commented May 25, 2021

Summary

This pull request fixes #1021 by updating the slack_sdk.models.views.View's constructor to convert a given state dict value to the ViewState class object.

As all other properties in View class are already converted to class objects, changing this part would be a great improvement in terms of consistency. The changed property is still compatible with the current type hint - Optional[Union[dict, ViewState]]. We are going to apply this change in the next minor version - 3.6.

Category (place an x in each of the [ ])

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.models (UI component builders)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.rtm (RTM client)
  • slack_sdk.signature (Request Signature Verifier)
  • /docs-src (Documents, have you run ./docs.sh?)
  • /docs-src-v2 (Documents, have you run ./docs-v2.sh?)
  • /tutorial (PythOnBoardingBot tutorial)
  • tests/integration_tests (Automated tests for this library)

Requirements (place an x in each [ ])

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run python setup.py validate after making the changes.

@seratch seratch added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented web-client Version: 3x labels May 25, 2021
@seratch seratch added this to the 3.6.0 milestone May 25, 2021
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:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been a potential bug - {} is a falsy value.

@@ -35,7 +35,7 @@
"callback_id": "view_4",
"external_id": "some-unique-id",
"state": {
"values": []
"values": {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been a potential issue of test data. The values usually cannot be an array.

@@ -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))
Copy link
Member Author

Choose a reason for hiding this comment

The 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.assertTrue(view.state is None or isinstance(view.state, dict)).

@@ -110,6 +111,18 @@ def test_valid_construction(self):
),
),
],
state=ViewState(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case, added test pattern to pass a ViewState object, not a dict.

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
Copy link
Member Author

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.

@seratch seratch force-pushed the issue-1021-view-state-init branch 3 times, most recently from fddee14 to ce98cc0 Compare May 25, 2021 12:14
@codecov
Copy link

codecov bot commented May 25, 2021

Codecov Report

Merging #1022 (ce98cc0) into main (66c8859) will decrease coverage by 2.98%.
The diff coverage is 80.00%.

❗ Current head ce98cc0 differs from pull request most recent head 291b432. Consider uploading reports for the commit 291b432 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1022      +/-   ##
==========================================
- Coverage   86.65%   83.66%   -2.99%     
==========================================
  Files          95       95              
  Lines        8789     8792       +3     
==========================================
- Hits         7616     7356     -260     
- Misses       1173     1436     +263     
Impacted Files Coverage Δ
slack_sdk/models/views/__init__.py 91.93% <80.00%> (+0.19%) ⬆️
slack_sdk/socket_mode/builtin/connection.py 36.13% <0.00%> (-31.94%) ⬇️
slack_sdk/socket_mode/websockets/__init__.py 59.80% <0.00%> (-30.40%) ⬇️
slack_sdk/socket_mode/websocket_client/__init__.py 60.76% <0.00%> (-27.70%) ⬇️
slack_sdk/socket_mode/aiohttp/__init__.py 55.79% <0.00%> (-25.37%) ⬇️
slack_sdk/socket_mode/builtin/internals.py 48.05% <0.00%> (-25.11%) ⬇️
slack_sdk/socket_mode/builtin/client.py 79.86% <0.00%> (-8.73%) ⬇️
slack_sdk/socket_mode/client.py 69.91% <0.00%> (-7.08%) ⬇️
slack_sdk/socket_mode/async_client.py 69.89% <0.00%> (-5.38%) ⬇️
slack_sdk/socket_mode/request.py 71.87% <0.00%> (-3.13%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 75b554a...291b432. Read the comment docs.

@seratch seratch force-pushed the issue-1021-view-state-init branch from ce98cc0 to 291b432 Compare May 25, 2021 12:20
@seratch
Copy link
Member Author

seratch commented May 26, 2021

To: reviewers, let me know if you have any comments.

@seratch
Copy link
Member Author

seratch commented May 27, 2021

Let me merge this one but feel free to write comments if you have any

@seratch seratch merged commit 35e2246 into slackapi:main May 27, 2021
@seratch seratch deleted the issue-1021-view-state-init branch May 27, 2021 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented Version: 3x web-client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initialize View state field to ViewState object based on type
1 participant