Fix transform() corrupting TRUE/FALSE/NULL column defaults into strings

* Fix transform() corrupting TRUE/FALSE/NULL column defaults

quote_default_value() passed keyword-literal defaults (TRUE, FALSE, NULL)
through self.quote(), wrapping them in quotes. So transform() rebuilt a
column declared "INTEGER DEFAULT TRUE" as "INTEGER DEFAULT 'TRUE'", and a
later default insert stored the text 'TRUE' instead of the integer 1
(likewise 'FALSE' for 0 and 'NULL' for null) - silent value corruption.

Return these keyword literals unquoted, as already done for the
CURRENT_TIME/DATE/TIMESTAMP literals.

PR #764
This commit is contained in:
Vincent Gao 2026-07-06 07:33:55 +02:00 committed by GitHub
commit a4acc3958c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 48 additions and 0 deletions

View file

@ -983,6 +983,11 @@ class Database:
if str(value).upper() in ("CURRENT_TIME", "CURRENT_DATE", "CURRENT_TIMESTAMP"):
return value
if isinstance(value, str) and value.upper() in ("TRUE", "FALSE", "NULL"):
# Keyword literals must stay unquoted; quoting them would turn the
# default into a string ('TRUE' instead of 1, 'NULL' instead of null).
return value
if str(value).endswith(")"):
# Expr
return "({})".format(value)