[Sqlalchemy-tickets] Issue #3955: connectionless execution + autocommit + ON CONFLICT DO NOTHING +
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2017-04-03 21:05:22
|
New issue 3955: connectionless execution + autocommit + ON CONFLICT DO NOTHING + no rows == boom https://bitbucket.org/zzzeek/sqlalchemy/issues/3955/connectionless-execution-autocommit-on Michael Bayer: ``` #!diff @@ -96,6 +97,33 @@ class OnConflictTest(fixtures.TablesTest): [(1, 'name1')] ) + def test_on_conflict_do_nothing_connectionless(self): + users = self.tables.users_xtra + + with testing.db.connect() as conn: + result = conn.execute( + insert(users).on_conflict_do_nothing( + constraint='uq_login_email'), + + dict(name='name1', login_email='email1') + ) + eq_(result.inserted_primary_key, [1]) + eq_(result.returned_defaults, (1,)) + + result = testing.db.execute( + insert(users).on_conflict_do_nothing( + constraint='uq_login_email' + ), + dict(name='name2', login_email='email1') + ) + eq_(result.inserted_primary_key, None) + eq_(result.returned_defaults, None) + + eq_( + testing.db.execute(users.select().where(users.c.id == 1)).fetchall(), + [(1, 'name1', 'email1', None)] + ) + @testing.provide_metadata def test_on_conflict_do_nothing_target(self): users = self.tables.users ``` the lack of row returned sends the connection into autoclose via result.fetchone(). then autocommit causes an exception, then it continues to be confused because the connection has been closed. |