Skip to content

Commit

Permalink
Comment-out invalid as_rowcount() + RETURNING tests for sqlite.
Browse files Browse the repository at this point in the history
The `sqlite3_changes()` interface does not populate the changes until
the statement containing the RETURNING has been consumed. The only
reason these tests were passing in the first place is likely because
they happened to be consumed in the first assertion, and then sat in the
statement cache and were re-run in the second assertion that checked the
rowcount.
coleifer committed Sep 21, 2022
1 parent 49a64bd commit 7333539
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tests/sqlite.py
Original file line number Diff line number Diff line change
@@ -2495,25 +2495,29 @@ def test_pk_set_properly(self):
kvr = KVR.create(key='k1', value=1)
self.assertEqual(kvr.key, 'k1')

@skip_if(sys.version_info >= (3, 11), 'test fails on 3.11')
def test_insert_behavior(self):
iq = User.insert({'username': 'u1'})
self.assertEqual(iq.execute(), 1)

iq = User.insert_many([{'username': 'u2'}, {'username': 'u3'}])
self.assertEqual(list(iq.execute()), [(2,), (3,)])

iq = User.insert_many([('u4',), ('u5',)]).as_rowcount()
self.assertEqual(iq.execute(), 2)
# NOTE: sqlite3_changes() does not return the inserted rowcount until
# the statement has been consumed. The fact that it returned 2 is a
# side-effect of the statement cache and our having consumed the query
# in the previous test assertion. So this test is invalid.
#iq = User.insert_many([('u4',), ('u5',)]).as_rowcount()
#self.assertEqual(iq.execute(), 2)

iq = KVR.insert({'key': 'k1', 'value': 1})
self.assertEqual(iq.execute(), 'k1')

iq = KVR.insert_many([('k2', 2), ('k3', 3)])
self.assertEqual(list(iq.execute()), [('k2',), ('k3',)])

iq = KVR.insert_many([('k4', 4), ('k5', 5)]).as_rowcount()
self.assertEqual(iq.execute(), 2)
# See note above.
#iq = KVR.insert_many([('k4', 4), ('k5', 5)]).as_rowcount()
#self.assertEqual(iq.execute(), 2)

def test_insert_on_conflict(self):
KVR.create(key='k1', value=1)

0 comments on commit 7333539

Please sign in to comment.