]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Asyncpg null query fix
authorCommanderKeynes <andrewjackson947@gmail.coma>
Tue, 7 Jan 2025 15:52:36 +0000 (10:52 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 7 Jan 2025 16:25:52 +0000 (11:25 -0500)
Adjusted the asyncpg dialect so that an empty SQL string, which is valid
for PostgreSQL server, may be successfully processed at the dialect level,
such as when using :meth:`.Connection.exec_driver_sql`. Pull request
courtesy Andrew Jackson.

Closes: #12220
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12220
Pull-request-sha: 45c94febee66b567040b1fbfa3a93079a1314f09

Change-Id: I870df9e31f4a229939e76c702724c25073329282
(cherry picked from commit 7bfb829f25c1bfe2139afe7875882298aaf345ba)

doc/build/changelog/unreleased_20/12220.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/postgresql/asyncpg.py
test/dialect/postgresql/test_dialect.py

diff --git a/doc/build/changelog/unreleased_20/12220.rst b/doc/build/changelog/unreleased_20/12220.rst
new file mode 100644 (file)
index 0000000..a4b30cc
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, postgresql
+    :tickets: 12220
+
+    Adjusted the asyncpg dialect so that an empty SQL string, which is valid
+    for PostgreSQL server, may be successfully processed at the dialect level,
+    such as when using :meth:`.Connection.exec_driver_sql`. Pull request
+    courtesy Andrew Jackson.
+
index 1761c8de53cb1d46966de45e13b796299099b853..523c47abcd0116f5b7b193052ac262987eb1cc72 100644 (file)
@@ -546,7 +546,8 @@ class AsyncAdapt_asyncpg_cursor:
                     status = prepared_stmt.get_statusmsg()
 
                     reg = re.match(
-                        r"(?:SELECT|UPDATE|DELETE|INSERT \d+) (\d+)", status
+                        r"(?:SELECT|UPDATE|DELETE|INSERT \d+) (\d+)",
+                        status or "",
                     )
                     if reg:
                         self.rowcount = int(reg.group(1))
index 892e2abc9be02a450c954ae5bca7700389b73996..109101011fc865f1885583ca04e7713242a11df5 100644 (file)
@@ -1040,6 +1040,12 @@ class MiscBackendTest(
     __only_on__ = "postgresql"
     __backend__ = True
 
+    @testing.fails_on(["+psycopg2"])
+    def test_empty_sql_string(self, connection):
+
+        result = connection.exec_driver_sql("")
+        assert result._soft_closed
+
     @testing.provide_metadata
     def test_date_reflection(self):
         metadata = self.metadata