It happened again:
-
It happened again:
Pytest crashing because of an OperationalError on SQLite due to an unexpected "None".
This is due to missing max_length argument for varchar fields.
Older versions of Django checked if max_length was missing, but newer versions only do when the database driver needs them. So when you develop on PostgreSQL and test on SQLite, this might be an error.
I still dislike that this behavior was changed.
-
Marijke Luttekesreplied to Marijke Luttekes last edited by
The irony is that thanks to my reading issues, this happened when I thought I'd correctly fixed all the occurrences but later discovered I missed one line above.
(Luckily, pytest-django prints the entire raw SQL query on higher verbosities, and I found the culprit through there.)
-
Ryan Hiebertreplied to Marijke Luttekes last edited by
@mahryekuh sounds like a place where a better error message would be a further improvement. The feature itself seems good, but does highlight my belief that it’s important to test with the same database you run in prod.
-
Marijke Luttekesreplied to Ryan Hiebert last edited by
@ryanhiebert The error message could be more descriptive.
PostgreSQL is the only database driver that doesn't require the max_length attribute, which makes it "special".
It's also (as far as I know) not as straightforward or fast to test with PG than it is with SQLite, so this is just one thing I have to remember.
However, I don't want to have to add max_length only for tests, so I'm now stuck with another issue (I want to get rid of max_length altogether).
-
Marijke Luttekesreplied to Marijke Luttekes last edited by
@ryanhiebert The bottom line is: The SQLite driver shouldn't do `VARCHAR(None)` when `varchar` alone is acceptable since modern SQLite apparently ignores the number without parentheses anyway if you add any.
(Section 3.1.1 https://sqlite.org/datatype3.html)