]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add quoted_name to pg8000 py_types
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 8 Aug 2017 17:30:49 +0000 (13:30 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 8 Aug 2017 21:25:28 +0000 (17:25 -0400)
Fixed bug where the pg8000 driver would fail if using
:meth:`.MetaData.reflect` with a schema name, since the schema name would
be sent as a "quoted_name" object that's a string subclass, which pg8000
doesn't recognize.   The quoted_name type is added to pg8000's
py_types collection on connect.

Change-Id: Id0f838320cb66563685e094e4eae2d5116100d27
Fixes: #4041
doc/build/changelog/unreleased_12/4041.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/postgresql/pg8000.py
test/dialect/postgresql/test_dialect.py

diff --git a/doc/build/changelog/unreleased_12/4041.rst b/doc/build/changelog/unreleased_12/4041.rst
new file mode 100644 (file)
index 0000000..ebcb723
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, postgresql
+    :tickets: 4041
+
+    Fixed bug where the pg8000 driver would fail if using
+    :meth:`.MetaData.reflect` with a schema name, since the schema name would
+    be sent as a "quoted_name" object that's a string subclass, which pg8000
+    doesn't recognize.   The quoted_name type is added to pg8000's
+    py_types collection on connect.
index 8c019a26daf10d7dec14e67eaddab50897063745..5f6cd0a3f648a0329eb87c2e0b041e1d2a28e6b1 100644 (file)
@@ -73,6 +73,7 @@ from .base import (
     _DECIMAL_TYPES, _FLOAT_TYPES, _INT_TYPES)
 import re
 from sqlalchemy.dialects.postgresql.json import JSON
+from ...sql.elements import quoted_name
 
 
 class _PGNumeric(sqltypes.Numeric):
@@ -244,6 +245,11 @@ class PGDialect_pg8000(PGDialect):
 
     def on_connect(self):
         fns = []
+
+        def on_connect(conn):
+            conn.py_types[quoted_name] = conn.py_types[unicode]
+        fns.append(on_connect)
+
         if self.client_encoding is not None:
             def on_connect(conn):
                 self.set_client_encoding(conn, self.client_encoding)
index 376ba081cf29bf921cb42c95e688d7187ea7a6ad..27e0ac065946dd985d2299a9abb92acfede5e026 100644 (file)
@@ -8,7 +8,8 @@ from sqlalchemy import testing
 import datetime
 from sqlalchemy import (
     Table, Column, select, MetaData, text, Integer, String, Sequence, Numeric,
-    DateTime, BigInteger, func, extract, SmallInteger, TypeDecorator)
+    DateTime, BigInteger, func, extract, SmallInteger, TypeDecorator, literal,
+    cast)
 from sqlalchemy import exc, schema
 from sqlalchemy.dialects.postgresql import base as postgresql
 import logging
@@ -225,6 +226,20 @@ class MiscTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL):
         finally:
             users.drop()
 
+    def test_quoted_name_bindparam_ok(self):
+        from sqlalchemy.sql.elements import quoted_name
+
+        with testing.db.connect() as conn:
+            eq_(
+                conn.scalar(
+                    select(
+                        [cast(
+                            literal(quoted_name("some_name", False)), String)]
+                    )
+                ),
+                "some_name"
+            )
+
     def test_preexecute_passivedefault(self):
         """test that when we get a primary key column back from
         reflecting a table which has a default value on it, we pre-