--- /dev/null
+.. change::
+ :tags: bug, postgresql
+ :tickets: 6106
+
+ The :class:`_postgresql.ENUM` datatype is PostgreSQL-native and therefore
+ should not be used with the ``native_enum=False`` flag. This flag is now
+ ignored if passed to the :class:`_postgresql.ENUM` datatype and a warning
+ is emitted; previously the flag would cause the type object to fail to
+ function correctly.
+
be used to emit SQL to a target bind.
"""
+ native_enum = kw.pop("native_enum", None)
+ if native_enum is False:
+ util.warn(
+ "the native_enum flag does not apply to the "
+ "sqlalchemy.dialects.postgresql.ENUM datatype; this type "
+ "always refers to ENUM. Use sqlalchemy.types.Enum for "
+ "non-native enum."
+ )
self.create_type = kw.pop("create_type", True)
super(ENUM, self).__init__(*enums, **kw)
__only_on__ = "postgresql > 8.3"
+ def test_native_enum_warnings(self):
+ """test #6106"""
+
+ with testing.expect_warnings(
+ "the native_enum flag does not apply to the "
+ "sqlalchemy.dialects.postgresql.ENUM datatype;"
+ ):
+ e1 = postgresql.ENUM("a", "b", "c", native_enum=False)
+
+ e2 = postgresql.ENUM("a", "b", "c", native_enum=True)
+ e3 = postgresql.ENUM("a", "b", "c")
+
+ is_(e1.native_enum, True)
+ is_(e2.native_enum, True)
+ is_(e3.native_enum, True)
+
def test_create_table(self, metadata, connection):
metadata = self.metadata
t1 = Table(
@testing.combinations(
sqltypes.ARRAY, postgresql.ARRAY, argnames="array_cls"
)
- @testing.combinations(sqltypes.Enum, postgresql.ENUM, argnames="enum_cls")
- def test_raises_non_native_enums(
- self, metadata, connection, array_cls, enum_cls
- ):
+ def test_raises_non_native_enums(self, metadata, connection, array_cls):
+ enum_cls = sqltypes.Enum
+
Table(
"my_table",
self.metadata,