You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When pk is specified by table A's insert call, it throws an index error if a different table has written a row with a higher rowid than exists in the first table. Here's a basic example:
fromsqlite_utilsimportDatabasedeftest_pk_for_insert(fresh_db):
user= {"id": "abc", "name": "david"}
fresh_db["users"].insert(user, pk="id")
fresh_db["comments"].insert_all(
[
{"id": "def", "text": "ok"},
{"id": "ghi", "text": "great"},
],
)
fresh_db["users"].insert(
user,
ignore=True,
# BUG: when specifying pk on the second insert call # db.py goes into a block it doesn't expect and we get the errorpk="id",
)
if__name__=="__main__":
db=Database("bug.db")
ifdb["users"].exists():
raiseValueError(
"bug only shows on a new database - remove bug.db before running the script"
)
test_pk_for_insert(db)
Oh and for context - this goes away if I use .upsert instead of insert(..., ignore=True), but I don't want to update the value if it's written, just do an insert if it's new. The code is basically:
So either comments or post could create the relevant user if those items exist. In cases where they both exist, I get this error. I need the pk because either call could create the table.
I believe this is related to #98.
When
pk
is specified by table A'sinsert
call, it throws an index error if a different table has written a row with a higher rowid than exists in the first table. Here's a basic example:The error is:
The issue is in this block:
sqlite-utils/sqlite_utils/db.py
Lines 2954 to 2958 in 2747257
relevant locals are:
pk
:'id'
result.lastrowid
:2
What's most interesting is the comment
# self.last_rowid will be 0 if a "INSERT OR IGNORE" happened
, which doesn't seem to be the case here.The text was updated successfully, but these errors were encountered: