summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/build/changelog/unreleased_12/4041.rst9
-rw-r--r--lib/sqlalchemy/dialects/postgresql/pg8000.py6
-rw-r--r--test/dialect/postgresql/test_dialect.py17
3 files changed, 31 insertions, 1 deletions
diff --git a/doc/build/changelog/unreleased_12/4041.rst b/doc/build/changelog/unreleased_12/4041.rst
new file mode 100644
index 000000000..ebcb7236c
--- /dev/null
+++ b/doc/build/changelog/unreleased_12/4041.rst
@@ -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.
diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py
index 8c019a26d..5f6cd0a3f 100644
--- a/lib/sqlalchemy/dialects/postgresql/pg8000.py
+++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py
@@ -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)
diff --git a/test/dialect/postgresql/test_dialect.py b/test/dialect/postgresql/test_dialect.py
index 376ba081c..27e0ac065 100644
--- a/test/dialect/postgresql/test_dialect.py
+++ b/test/dialect/postgresql/test_dialect.py
@@ -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-