diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-27 13:09:04 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-27 13:13:52 -0400 |
| commit | 70c51bbe5e0c0f7feb4695b2a38140ec53282c27 (patch) | |
| tree | b06d41d3e299c3e848b6ace6e773b9284291cbf9 /lib/sqlalchemy/sql | |
| parent | cf329ec33153307968828b46a4466850ebcf374e (diff) | |
| download | sqlalchemy-70c51bbe5e0c0f7feb4695b2a38140ec53282c27.tar.gz | |
have SchemaType inherit schema from metadata
Fixed very old issue where the :class:`_types.Enum` datatype would not
inherit the :paramref:`_schema.MetaData.schema` parameter of a
:class:`_schema.MetaData` object when that object were passed to the
:class:`_types.Enum` using :paramref:`_types.Enum.metadata`.
Fixes: #6373
Change-Id: Ie77d5e8cbc0bd7bfd0039fb60a4a0bde2df58ca9
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/sqltypes.py | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index 489594b85..024b9f01e 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -1105,6 +1105,8 @@ class SchemaType(SchemaEventTarget): def _set_table(self, column, table): if self.inherit_schema: self.schema = table.schema + elif self.metadata and self.schema is None and self.metadata.schema: + self.schema = self.metadata.schema if not self._create_events: return @@ -1365,6 +1367,16 @@ class Enum(Emulated, String, SchemaType): only dropped when ``drop_all()`` is called for that ``Table`` object's metadata, however. + The value of the :paramref:`_schema.MetaData.schema` parameter of + the :class:`_schema.MetaData` object, if set, will be used as the + default value of the :paramref:`_types.Enum.schema` on this object + if an explicit value is not otherwise supplied. + + .. versionchanged:: 1.4.12 :class:`_types.Enum` inherits the + :paramref:`_schema.MetaData.schema` parameter of the + :class:`_schema.MetaData` object if present, when passed using + the :paramref:`_types.Enum.metadata` parameter. + :param name: The name of this type. This is required for PostgreSQL and any future supported database which requires an explicitly named type, or an explicitly named constraint in order to generate @@ -1388,12 +1400,22 @@ class Enum(Emulated, String, SchemaType): this parameter specifies the named schema in which the type is present. - .. note:: + If not present, the schema name will be taken from the + :class:`_schema.MetaData` collection if passed as + :paramref:`_types.Enum.metadata`, for a :class:`_schema.MetaData` + that includes the :paramref:`_schema.MetaData.schema` parameter. + + .. versionchanged:: 1.4.12 :class:`_types.Enum` inherits the + :paramref:`_schema.MetaData.schema` parameter of the + :class:`_schema.MetaData` object if present, when passed using + the :paramref:`_types.Enum.metadata` parameter. + + Otherwise, if the :paramref:`_types.Enum.inherit_schema` flag is set + to ``True``, the schema will be inherited from the associated + :class:`_schema.Table` object if any; when + :paramref:`_types.Enum.inherit_schema` is at its default of + ``False``, the owning table's schema is **not** used. - The ``schema`` of the :class:`.Enum` type does not - by default make use of the ``schema`` established on the - owning :class:`_schema.Table`. If this behavior is desired, - set the ``inherit_schema`` flag to ``True``. :param quote: Set explicit quoting preferences for the type's name. |
