diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-09-03 14:14:39 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-10-12 13:52:06 -0400 |
commit | 9e82f32f274e649b04740c819d21ba232c89cfff (patch) | |
tree | 15ba969d68aa914ffff413d1db3d2697761ba247 /lib/sqlalchemy/sql/base.py | |
parent | a3e2eb7c3c3fe6b2bebd14a7e9d661b2b4519d1f (diff) | |
download | sqlalchemy-9e82f32f274e649b04740c819d21ba232c89cfff.tar.gz |
Deprecate duplicated column names in Table definition
The :class:`_schema.Table` class now raises a deprecation warning
when columns with the same name are defined. To replace a column a new
parameter :paramref:`_schema.Table.append_column.replace_existing` was
added to the :meth:`_schema.Table.append_column` method.
The :meth:`_expression.ColumnCollection.contains_column` will now
raises an error when called with a string, suggesting the caller
to use ``in`` instead.
Co-authored-by: Federico Caselli <cfederico87@gmail.com>
Change-Id: I1d58c8ebe081079cb669e7ead60886ffc1b1a7f5
Diffstat (limited to 'lib/sqlalchemy/sql/base.py')
-rw-r--r-- | lib/sqlalchemy/sql/base.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py index f9b5ce7e1..f912163bc 100644 --- a/lib/sqlalchemy/sql/base.py +++ b/lib/sqlalchemy/sql/base.py @@ -956,12 +956,12 @@ class SchemaEventTarget(object): """ - def _set_parent(self, parent): + def _set_parent(self, parent, **kw): """Associate with this SchemaEvent's parent object.""" - def _set_parent_with_dispatch(self, parent): + def _set_parent_with_dispatch(self, parent, **kw): self.dispatch.before_parent_attach(self, parent) - self._set_parent(parent) + self._set_parent(parent, **kw) self.dispatch.after_parent_attach(self, parent) @@ -1185,7 +1185,16 @@ class ColumnCollection(object): ) def contains_column(self, col): - return col in self._colset + """Checks if a column object exists in this collection""" + if col not in self._colset: + if isinstance(col, util.string_types): + raise exc.ArgumentError( + "contains_column cannot be used with string arguments. " + "Use ``col_name in table.c`` instead." + ) + return False + else: + return True def as_immutable(self): return ImmutableColumnCollection(self) @@ -1302,6 +1311,7 @@ class DedupeColumnCollection(ColumnCollection): """ def add(self, column, key=None): + if key is not None and column.key != key: raise exc.ArgumentError( "DedupeColumnCollection requires columns be under " |