-
Notifications
You must be signed in to change notification settings - Fork 20
Conversation
@@ -121,7 +121,7 @@ def drop_postgresql_database(psycopg2, user, host, port, db): | |||
conn = psycopg2.connect(user=user, host=host, port=port) | |||
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) | |||
cur = conn.cursor() | |||
cur.execute('DROP DATABASE IF EXISTS %s' % db) | |||
cur.execute('DROP DATABASE IF EXISTS %s;' % 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.
I don't understand why other queries work without that semicolon, but this one doesn't.
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.
What's an example of a query that works without terminating semicolon?
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.
We have cur.execute('CREATE DATABASE ' + db)
. Also the DROP DATABASE
works (I do get errors from it if a buggy test leaves an open database connection). I cannot find explicit rules about semicolons, but it seems the single statement passed via cur.execute
doesn't need a trailing one.
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.
Fair enough. The postgres fixture is unusable for me without the semicolon
since the db isn't cleared. You're saying the fixture works for you without
the semicolon?
On 10 Sep 2016 12:11, "Michał Masłowski" notifications@github.com wrote:
In src/pytest_dbfixtures/factories/postgresql.py
#185 (comment)
:@@ -121,7 +121,7 @@ def drop_postgresql_database(psycopg2, user, host, port, db):
conn = psycopg2.connect(user=user, host=host, port=port)
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
cur = conn.cursor()
- cur.execute('DROP DATABASE IF EXISTS %s' % db)
- cur.execute('DROP DATABASE IF EXISTS %s;' % db)
We have cur.execute('CREATE DATABASE ' + db). Also the DROP DATABASE
works (I do get errors from it if a buggy test leaves an open database
connection). I cannot find explicit rules about semicolons, but it seems
the single statement passed via cur.execute doesn't need a trailing one.—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/ClearcodeHQ/pytest-dbfixtures/pull/185/files/492e2c8e62eac3b385abc095bd46bf2d08c93f9d#r78275121,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADHzHpb3TlFNnWr09vJuzjxfvzUGNtzXks5qooJggaJpZM4J5j-u
.
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.
yes, we haven't had any problems with this except for errors we get when some process used in integration tests doesn't close the connection at the end of the test.
I'm still going to accept this for the sake of correspondence with other tools (better to add comma after SQL statement here, than forget it about in other places.
Still even documentation doesn't always use the semicolon for single statement execute: http://initd.org/psycopg/docs/usage.html
It could help to get to the issue, if you'd write something about your test setup or test case.
This PR fixes the following issues: