-
Notifications
You must be signed in to change notification settings - Fork 71
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: Refactor SQLConnector
connection handling
#1394
feat: Refactor SQLConnector
connection handling
#1394
Conversation
(re: mypy fix; issue was caching the _engine property). I used an lru_cache decorator at first, but there doesn't seem to be any real way to handle typing for a lru_cache-wrapped function that returns something— see here. So instead I just used another property to cache it. Maybe not the most pythonic(?) but it works fine. Another option is to |
Codecov Report
@@ Coverage Diff @@
## main #1394 +/- ##
==========================================
+ Coverage 85.19% 85.39% +0.19%
==========================================
Files 54 54
Lines 4722 4737 +15
Branches 803 808 +5
==========================================
+ Hits 4023 4045 +22
+ Misses 507 501 -6
+ Partials 192 191 -1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@qbatten this is great, thanks for all your work on connection handling 🙏 As we are pre-1.0 for the SDK, and especially since there are far fewer users of the SQLConnector at this point, I think the breaking changes are OK. However, it would be good to proactively reach out to the Taps/Targets we know about that would potentially be impacted (using Hub data), to make sure they are pinning their SDK version and are aware of the changes 🙂 I can help with that 👍 |
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.
LGTM 🚢 Minor suggestions around deprecation warnings 👍
Add deprecation warnings. Co-authored-by: Ken Payne <[email protected]>
for more information, see https://pre-commit.ci
Co-authored-by: Edgar R. M. <[email protected]>
Test coverage! Woohoo! |
@qbatten this is looking great 😄 |
SQLConnector
connection handling
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.
This is a draft PR that proposes a solution to issue #1393.
Broad overview:
self._connect()
as a context manager. This rule is put into place where it's possible to do so without making a breaking change._connection
is removed altogether. The tap no longer accepts that argument on init, and we don't store a single connection at allcreate_sqlalchemy_connection
was called (or for anyone who didn't respect the protectedness of _connection).connection
still exists, it just callscreate_sqlalchemy_connection
. So this is a slightly breaking change—- it returns a new connection instead of the _connection that prviously had been preserved on the instance.create_sqlalchemy_engine
now just returns self._engine, since we have an engine on this object anyway.create_sqlalchemy_connection
now opens a connection using self._engine and returns the open connection.Detailed changes in functionality:
self._connect()
is added. This is the correct way to open connections now—- you use it as a context manager, exactly as you would sqlalchemy.engine.connect()... in fact currently it just directly wraps that._engine
.create_sqlalchemy_connection
callsself._engine
now instead ofself.create_sqlalchemy_engine
, since the connector now has an engine. This and the next item help extricate and disconnect these soon-to-be-deprecated methods.create_sqlalchemy_engine
now callsself._engine
instead of making the engine itself.📚 Documentation preview 📚: https://meltano-sdk--1394.org.readthedocs.build/en/1394/