-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
support both sqlalchemy engines and connections #10105
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
support both sqlalchemy engines and connections #10105
Conversation
d4a42a6
to
6e80100
Compare
This looks good and would also resolve #7877 I believe. |
@graingert Thanks for working on this! Certainly look also to the discussion in #7877. At the end there is link to a patch of @tr11 which does something similar. Some quick thoughts:
|
ef122d6
to
5c7d352
Compare
@graingert Some of the tests keep on running. I already restarted them a few times, so it seems this is caused by this PR. Did you try to run the tests locally? (only the sql tests is enough) |
5fd3d9a
to
9c1a737
Compare
@@ -2180,6 +2237,7 @@ def setUp(self): | |||
except: | |||
pass | |||
else: | |||
self.addCleanup(self._try_close_db) |
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.
For the tests to pass on my machine I need to close the database connection after each test.
40e09e0
to
71fd12e
Compare
@jorisvandenbossche I've debugged all the tests. Once the travis builds pass I'll remove the commits |
I think |
40e09e0
to
56094aa
Compare
@jorisvandenbossche @artemyk I can't replicate the issues in 4b2f087...1037144 locally do you have any ideas? |
@artemyk @jorisvandenbossche I'm pretty sure I've got it now. I'll clean up this PR with a repo tomorrow |
When running with two queries at the same time, if one raises a warning and the other doesn't PyMySQL raises a TypeError. proc = """DROP PROCEDURE IF EXISTS get_testdb;
CREATE PROCEDURE get_testdb ()
BEGIN
SELECT * FROM test_procedure;
END""" The DROP PROCEDURE was raising a warning on Travis because the get_testdb procedure was missing, however on my local machine I was not destroying/rebuilding the database each test run which meant I still had the "get_testdb" procedure. |
@graingert Glad you've figured it out. I'm not sure |
74e0a11
to
c34fd2b
Compare
pls rebase on master, some issues have been fixed with the builds |
e15f56a
to
66283c3
Compare
@jorisvandenbossche done @jreback yep, rebase fixed those issues thanks. |
@jorisvandenbossche @jreback casual nudge |
@jorisvandenbossche @jreback hey guys, I really need this feature in production... can you guys merge this if you think it's useful |
@graingert lgtm, but @jorisvandenbossche may have some more comments. if you are actually running off of master (in production)?, then you can just merge this into your local master. This would be in 0.17.0 which won't be out for prob 2 months. |
Sorry for the slow response. But I will look at it this evening, I promise! Short comment: ideally, I would like to see a test that now fails (so a test that is only run for the test class that uses a connection, and not an engine), to be sure that with a later refactor this ability is not lost again. |
66283c3
to
9d72dd9
Compare
Yes, I saw that, but if I understand correctly, this test is ran for both the engine tests as the connection tests? |
@@ -139,7 +139,7 @@ def execute(sql, con, cur=None, params=None): | |||
---------- | |||
sql : string | |||
Query to be executed | |||
con : SQLAlchemy engine or sqlite3 DBAPI2 connection | |||
con : SQLAlchemy connectable or sqlite3 DBAPI2 connection |
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 worry a bit that the term 'connectable' is not really known to most users? Maybe just use engine/connection
?
Ah I see what you mean |
5ec7a24
to
ec5c9d9
Compare
self.__tx.rollback() | ||
self.conn.close() | ||
self.conn = self.__engine | ||
self.pandasSQL = sql.SQLDatabase(self.__engine) |
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.
Does this line have to be here?
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.
not currently, it's just so this class cleans up everything back to how it was from the superclass's setup.
This is for principal of least surprise for those superclasses.
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.
OK, but before each test is run, the setup will overwrite this anyway again?
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 so that when the tearDown method gets called in the superclasses the instance is exactly how that superclass set it up in setUp
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.
ah, yes, OK
Thanks for adding the temp table test! Gave it a last round, see last comments. Last question: can you squash the commits? Then I will merge when it is green again |
update pymysql to 0.6.3 to avoid cursor bugs Add documentation and tests for SQLAlchemy connectables explicit reference to connection/engine in docs Temporary table test pass compile the connectable
a9583bc
to
7327f6b
Compare
fixed, rebased, squashed It's party time: 🍰 ✨ |
@graingert Thanks a lot! (for the contribution, and also for the patience ..) |
support both sqlalchemy engines and connections
Woot, thanks very much! |
Fixes #7877