-
Notifications
You must be signed in to change notification settings - Fork 179
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
[POC] Added Support for AsyncSession in SQLAlchemy 1.4+ #1413
base: main
Are you sure you want to change the base?
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
Hi @zikphil thanks for the contribution! I'm sorry it's taken us a few days to get to it — we've been pretty heads-down on getting ready for tomorrow's release. I'll make sure this PR gets reviewed ASAP |
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.
Thanks for this, this is awesome -- glad its not too bad to get this working.
To get this merged, I think we'll need to do some testing in sqlalchemy 1.3
, which we need to continue supporting. Right now I'm pretty sure there are a few ways this breaks compatibility.
Do you think you'd have time to do that testing? We'd love to get this out in the next release (in two weeks)
Please review the new implementation. I have split it out in separate files and added a condition for SQLAlchemy => 1.4 |
languages/python/sqlalchemy-oso/sqlalchemy_oso/async_session.py
Outdated
Show resolved
Hide resolved
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.
I think from an implementation standpoint this looks good to me. Do you think you could add a few tests, one for each of async_authorized_sessionmaker
and async_scoped_session
? I would think you could copy some tests verbatim from test_sqlalchemy.py
and add @pytest.mark.async
to make them asynchronous.
You'd also probably need to skip the test file during the sqlalchemy 1.3 tests (which the test suite runs in parallel with tox
). You should be able to use pytest.mark.skip
with allow_module_level=True
to do that (see: https://docs.pytest.org/en/latest/how-to/skipping.html#skip).
Lemme know if you need any tips on that. Thanks again for this contribution -- very excited to have this in.
Hi @zikphil - do you have a chance to move forward with this PR? We had used it with a handful of calls so far and it worked fine, would be great to have it operating on top of |
Im adding a PoC for AsyncSession support in the latest sqlalchemy-oso module.
2 functions are added: authorized_async_sessionmaker and async_scoped_session, both are expecting AsyncSessions as opposed to normal Session.
SQLAlchemy converts all code to Sync when time comes to process signals so there shouldn't be a need for any modifications there. I have tested with the following code from your tutorial and got the expected output:
https://gist.github.com/zikphil/9b0c7d70b789796bcbcc56528e41ea51
Feel free to adapt this code as you see fit.