From: Mike Bayer Date: Thu, 1 May 2025 13:43:29 +0000 (-0400) Subject: fix sqlite localtimestamp function X-Git-Tag: rel_2_0_41~13^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09b70d72f555ba7f9dc731e60bf104d451bbd257;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fix sqlite localtimestamp function Fixed and added test support for a few SQLite SQL functions hardcoded into the compiler most notably the "localtimestamp" function which rendered with incorrect internal quoting. Fixes: #12566 Change-Id: Id5bd8dc7841f0afab7df031ba5c0854dab845a1d (cherry picked from commit d689e465edf11308b0efba018aa84c3d79ccbaab) --- diff --git a/doc/build/changelog/unreleased_20/12566.rst b/doc/build/changelog/unreleased_20/12566.rst new file mode 100644 index 0000000000..194936f967 --- /dev/null +++ b/doc/build/changelog/unreleased_20/12566.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, sqlite + :tickets: 12566 + + Fixed and added test support for a few SQLite SQL functions hardcoded into + the compiler most notably the "localtimestamp" function which rendered with + incorrect internal quoting. diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index bf632f1fa4..719c0860b4 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -1367,7 +1367,7 @@ class SQLiteCompiler(compiler.SQLCompiler): return "CURRENT_TIMESTAMP" def visit_localtimestamp_func(self, func, **kw): - return 'DATETIME(CURRENT_TIMESTAMP, "localtime")' + return "DATETIME(CURRENT_TIMESTAMP, 'localtime')" def visit_true(self, expr, **kw): return "1" diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index c2c63e9ef0..0d8c671402 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -785,6 +785,16 @@ class DialectTest( " y INTEGER GENERATED ALWAYS AS (x + 2)%s)" % text, ) + @testing.combinations( + (func.localtimestamp(),), + (func.now(),), + (func.char_length("test"),), + (func.aggregate_strings("abc", ","),), + argnames="fn", + ) + def test_builtin_functions_roundtrip(self, fn, connection): + connection.execute(select(fn)) + class AttachedDBTest(fixtures.TablesTest): __only_on__ = "sqlite" @@ -969,7 +979,7 @@ class SQLTest(fixtures.TestBase, AssertsCompiledSQL): def test_localtime(self): self.assert_compile( - func.localtimestamp(), 'DATETIME(CURRENT_TIMESTAMP, "localtime")' + func.localtimestamp(), "DATETIME(CURRENT_TIMESTAMP, 'localtime')" ) def test_constraints_with_schemas(self):