I love SQLite but OMG the bugs from namespace pollution in Python

So I was doing an insert:


...
try:
    self.cursor.execute(self.schemas[schema_key], params)
    rows_affected = cursor.rowcount
    self.commit()
except sqlite3.IntegrityError as e:
    rows_affected = -1
finally:
    self.lock.release() # END PRIVILEGED CODE
    return rows_affected

Do you see the bug that caused a silent failure of the INSERT statement?

Yep, that should be self.cursor.rowcount in the try block; there were zero diagnostics and zero exceptions and zero failures, just nothing being written to the database.

Literally zero diagnostics, I just had to mess with the code until I saw the issue. Presumably I was invoking some code hook into the cursor package namespace and silently trashing the insert before the commit happened; still not sure, because I think that at one point I may have been doing the commit BEFORE asking for the rowcount.

Argh.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *