summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql/base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-11-16 20:11:18 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-11-16 20:11:18 -0500
commit200e70b9745f1f344be4a35bb8f2b5f01b40d467 (patch)
tree4b93ebd04ea1f9f68b4575646b88acfa70ce3666 /lib/sqlalchemy/dialects/postgresql/base.py
parent3fc6c40ea77c971d3067dab0fdf57a5b5313b69b (diff)
downloadsqlalchemy-200e70b9745f1f344be4a35bb8f2b5f01b40d467.tar.gz
accommodate NULL format_type()
Made an adjustment to how the PostgreSQL dialect considers column types when it reflects columns from a table, to accommodate for alternative backends which may return NULL from the PG ``format_type()`` function. Fixes: #8748 Change-Id: I6178287aac567210a76afaa5805b825daa7fa4db
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index a908ed6b7..41064de10 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -3489,12 +3489,19 @@ class PGDialect(default.DefaultDialect):
generated = row_dict["generated"]
identity = row_dict["identity_options"]
- # strip (*) from character varying(5), timestamp(5)
- # with time zone, geometry(POLYGON), etc.
- attype = attype_pattern.sub("", format_type)
+ if format_type is None:
+ no_format_type = True
+ attype = format_type = "no format_type()"
+ is_array = False
+ else:
+ no_format_type = False
+
+ # strip (*) from character varying(5), timestamp(5)
+ # with time zone, geometry(POLYGON), etc.
+ attype = attype_pattern.sub("", format_type)
- # strip '[]' from integer[], etc. and check if an array
- attype, is_array = _handle_array_type(attype)
+ # strip '[]' from integer[], etc. and check if an array
+ attype, is_array = _handle_array_type(attype)
# strip quotes from case sensitive enum or domain names
enum_or_domain_key = tuple(util.quoted_token_parser(attype))
@@ -3589,6 +3596,12 @@ class PGDialect(default.DefaultDialect):
coltype = coltype(*args, **kwargs)
if is_array:
coltype = self.ischema_names["_array"](coltype)
+ elif no_format_type:
+ util.warn(
+ "PostgreSQL format_type() returned NULL for column '%s'"
+ % (name,)
+ )
+ coltype = sqltypes.NULLTYPE
else:
util.warn(
"Did not recognize type '%s' of column '%s'"