diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-01-14 20:48:01 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-01-14 20:48:01 +0000 |
| commit | 37b7e458c201a2f7788f3db8d85bed2ab2f8e190 (patch) | |
| tree | 369643daf70a7191bfab2f849386d3ecb90f92cb /lib | |
| parent | 76a7818013b1803876da7f51ec1601a25cb1e78b (diff) | |
| download | sqlalchemy-37b7e458c201a2f7788f3db8d85bed2ab2f8e190.tar.gz | |
- use ForeignKey.column as _colspec source in Column._make_proxy(), preventing needless
redundant string arithmetic in memoized ForeignKey.column method
- _pre_existing_column attribute becomes optional, only needed for original Table-bound column, not proxies
- compare two ForeignKeys based on target_fullname, don't assume self._colspec is a string
- Fixed bug when overriding a Column with a ForeignKey
on a reflected table, where derived columns (i.e. the
"virtual" columns of a select, etc.) would inadvertently
call upon schema-level cleanup logic intended only
for the original column. [ticket:1278]
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/schema.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index d454bc7cf..c4f9a2895 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -666,7 +666,9 @@ class Column(SchemaItem, expression.ColumnClause): if getattr(self, 'table', None) is not None: raise exc.ArgumentError("this Column already has a table!") - self._pre_existing_column = table._columns.get(self.key) + if self.key in table._columns: + # note the column being replaced, if any + self._pre_existing_column = table._columns.get(self.key) table._columns.replace(self) if self.primary_key: @@ -734,11 +736,17 @@ class Column(SchemaItem, expression.ColumnClause): (such as an alias or select statement). """ - fk = [ForeignKey(f._colspec) for f in self.foreign_keys] - c = Column(name or self.name, self.type, self.default, key = name or self.key, primary_key = self.primary_key, nullable = self.nullable, quote=self.quote, *fk) + fk = [ForeignKey(f.column) for f in self.foreign_keys] + c = Column( + name or self.name, + self.type, + self.default, + key = name or self.key, + primary_key = self.primary_key, + nullable = self.nullable, + quote=self.quote, *fk) c.table = selectable c.proxies = [self] - c._pre_existing_column = self._pre_existing_column selectable.columns.add(c) if self.primary_key: selectable.primary_key.add(c) @@ -924,10 +932,10 @@ class ForeignKey(SchemaItem): raise exc.InvalidRequestError("This ForeignKey already has a parent !") self.parent = column - if self.parent._pre_existing_column is not None: + if hasattr(self.parent, '_pre_existing_column'): # remove existing FK which matches us for fk in self.parent._pre_existing_column.foreign_keys: - if fk._colspec == self._colspec: + if fk.target_fullname == self.target_fullname: self.parent.table.foreign_keys.remove(fk) self.parent.table.constraints.remove(fk.constraint) |
