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

feat: #1276 add Asyncio SQLAlchemy support #1633

Merged
merged 7 commits into from
Jan 28, 2025

Conversation

galuszkak
Copy link
Contributor

Summary

Add support for Asyncio SQLAlchemy Installation and StateStore

Testing

Category

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

Requirements

  • 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 python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh after making the changes.

@seratch seratch added enhancement M-T: A feature request for new functionality Version: 3x oauth area:async labels Jan 14, 2025
@seratch seratch self-assigned this Jan 14, 2025
@seratch seratch added this to the 3.x milestone Jan 14, 2025
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

Left a few comments; Also, it seems the tests fail even for supported Python runtime versions. Could you check the issue?

slack_sdk/oauth/installation_store/sqlalchemy/__init__.py Outdated Show resolved Hide resolved
slack_sdk/oauth/installation_store/sqlalchemy/__init__.py Outdated Show resolved Hide resolved
tests/slack_sdk/oauth/state_store/test_async_sqlalchemy.py Outdated Show resolved Hide resolved
@galuszkak galuszkak force-pushed the feature/async-sqlalchemy branch from 4be23e7 to bdcea76 Compare January 14, 2025 16:26
@galuszkak
Copy link
Contributor Author

@seratch will look into that probably today. The problem is that my tests are passing, it just something happens later in tests that they are braking - I think it's somehow related to retrieving asyncio loop by std library.

@galuszkak galuszkak force-pushed the feature/async-sqlalchemy branch from bdcea76 to 69822e9 Compare January 14, 2025 16:41
@galuszkak
Copy link
Contributor Author

I've identified the source of the test failures @seratch. The original async_test helper created a single event loop and set it globally, which was the core of the problem. unittest.IsolatedAsyncioTestCase uses an asyncio runner that closes the event loop in its finally block. This meant that tests after the first were trying to use an already closed loop. By changing async_test to generate a new loop for each test, the problem is solved, and all tests are passing in the latest Python versions. This fix works because, while the decorator creates a new loop, the runner's finally block was closing the previously set loop, leading to the RuntimeError: There is no current event loop in thread 'MainThread'.

I assume I have to still rework this to make it work with Python 3.6 and 3.7 so in the end I will revert that - but it was nice to find root cause of this.

@galuszkak
Copy link
Contributor Author

I've tested locally now with support from Python 3.6/3.7

Testing with Python 3.7 I got

855 passed, 5 skipped, 23 warnings in 239.12s (0:03:59)

On my M1 Macbook.

@galuszkak
Copy link
Contributor Author

@seratch not sure why the test on 3.13 fail - but looks like some flaky test - it passed here on same commit:
https://github.com/galuszkak/python-slack-sdk/actions/runs/12856762928/job/35843837357

Can we re run those?

Copy link

codecov bot commented Jan 28, 2025

Codecov Report

Attention: Patch coverage is 93.75000% with 10 lines in your changes missing coverage. Please review.

Project coverage is 85.19%. Comparing base (fcd0a35) to head (45771a5).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
slack_sdk/oauth/state_store/sqlalchemy/__init__.py 84.78% 7 Missing ⚠️
...dk/oauth/installation_store/sqlalchemy/__init__.py 97.36% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1633      +/-   ##
==========================================
+ Coverage   85.06%   85.19%   +0.12%     
==========================================
  Files         113      113              
  Lines       12665    12823     +158     
==========================================
+ Hits        10774    10924     +150     
- Misses       1891     1899       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@seratch seratch modified the milestones: 3.x, 3.34.1 Jan 28, 2025
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

Looks great to me; thank you so much for taking the time to complete this PR!

@seratch seratch merged commit c77b863 into slackapi:main Jan 28, 2025
13 checks passed
@seratch
Copy link
Member

seratch commented Jan 28, 2025

We will add one more minor change to the next release, which includes your contribution. Until it's released, please copy and paste these source files in your project.

@galuszkak
Copy link
Contributor Author

galuszkak commented Jan 28, 2025

Don't need to copy paste ;) - in uv you can just do this - pinpoint branch for the time being:

[project]
name = "ProjectName"
dependencies = [
    "slack-bolt>=1.21.3",
    "slack-sdk",
    "sqlalchemy[asyncio]>=2.0.36",
]

[tool.uv]
dev-dependencies = [
    "pytest>=8.3.4",
]

[tool.uv.sources]
slack-sdk = { git = "https://github.com/galuszkak/python-slack-sdk", branch = "feature/async-sqlalchemy" }

@seratch
Copy link
Member

seratch commented Jan 28, 2025

Ah, yeah it sounds great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:async cla:signed enhancement M-T: A feature request for new functionality oauth Version: 3x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants