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))
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'"
from sqlalchemy.testing.assertions import ComparesIndexes
from sqlalchemy.testing.assertions import eq_
from sqlalchemy.testing.assertions import expect_raises
+from sqlalchemy.testing.assertions import expect_warnings
from sqlalchemy.testing.assertions import is_
from sqlalchemy.testing.assertions import is_false
from sqlalchemy.testing.assertions import is_true
+from sqlalchemy.types import NullType
class ReflectionFixtures:
dialect.ischema_names["my_custom_type"] = self.CustomType
self._assert_reflected(dialect)
+ def test_no_format_type(self):
+ """test #8748"""
+
+ dialect = postgresql.PGDialect()
+ dialect.ischema_names = dialect.ischema_names.copy()
+ dialect.ischema_names["my_custom_type"] = self.CustomType
+
+ with expect_warnings(
+ r"PostgreSQL format_type\(\) returned NULL for column 'colname'"
+ ):
+ row_dict = {
+ "name": "colname",
+ "table_name": "tblname",
+ "format_type": None,
+ "default": None,
+ "not_null": False,
+ "comment": None,
+ "generated": "",
+ "identity_options": None,
+ }
+ column_info = dialect._get_columns_info(
+ [row_dict], {}, {}, "public"
+ )
+ assert ("public", "tblname") in column_info
+ column_info = column_info[("public", "tblname")]
+ assert len(column_info) == 1
+ column_info = column_info[0]
+ assert isinstance(column_info["type"], NullType)
+
class IntervalReflectionTest(fixtures.TestBase):
__only_on__ = "postgresql"