-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sqlite-utils insert errors should show SQL and parameters, if possible #309
Comments
Yeah this error message could certainly be more helpful. I thought import sqlite3
db = sqlite3.connect(":memory:")
caught = []
try:
db.execute("create table foo (number integer)")
db.execute("insert into foo (number) values (?)", [34223049823094832094802398430298048240])
except Exception as e:
print(e)
caught.append(e)
isinstance(caught[0], OverflowError) Here's where that happens in the Python |
Steps to reproduce:
|
I'm going to use a bit of a dirty trick for this one: I'm going to recursively inspect the stack on an error and try to find the That way I can handle this all at the CLI layer without changing the exceptions that are being raised by the Python library. |
|
Demo:
|
TIL about how the stack inspection works: https://til.simonwillison.net/python/find-local-variables-in-exception-traceback |
I've tried several approaches, but this is the current one:
In all cases, I get this error:
I googled the error and checked SO answers and advice, all good. I changed my JSON file to not use integers so I no longer get this error. Of course, that makes using the database a bit harder, so I also tried to solve the problem by modifying DB structure (while using integers in JSON).
If change all
INTEGER
Data Types to something else (STRING
,TEXT
) and try to import again using--truncate
, I still get this error. I suppose I should tell sqlite-utils which columns should use non-INTEGER Data Type rather than rely on it to check my SQL table configuration.If that is the case, can this error be a bit more specific for easier troubleshooting - maybe tell us which which record caused the problem when that error is thrown?
My table has 60+ columns, many of which use 64-bit integers (not all records are large or known in advance), so while I can modify JSON to use strings instead of integers, it decreases usability and finding out which records have values for which SQLite integers aren't sufficient requires some work (I'm thinking about parsing all integers with
jq
and sorting output by length to identify those columns, but I'd prefer if sqlite-utils could tell me that).My environment:
The text was updated successfully, but these errors were encountered: