summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/schema.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-10-18 20:01:45 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-10-18 20:01:45 -0400
commit73669c7284548d0e5ab2147f66174c301e732650 (patch)
treed3d201b4528d41f661a39430801785b228c10760 /lib/sqlalchemy/sql/schema.py
parent71e043aaae1ff9cbf0597846b4cfdf645a46ebdf (diff)
downloadsqlalchemy-73669c7284548d0e5ab2147f66174c301e732650.tar.gz
- The :meth:`.Table.tometadata` method now produces copies of
all :attr:`.SchemaItem.info` dictionaries from all :class:`.SchemaItem` objects within the structure including columns, constraints, foreign keys, etc. As these dictionaries are copies, they are independent of the original dictionary. Previously, only the ``.info`` dictionary of :class:`.Column` was transferred within this operation, and it was only linked in place, not copied. [ticket:2716]
Diffstat (limited to 'lib/sqlalchemy/sql/schema.py')
-rw-r--r--lib/sqlalchemy/sql/schema.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py
index 90c4fb0dd..40bd5b90a 100644
--- a/lib/sqlalchemy/sql/schema.py
+++ b/lib/sqlalchemy/sql/schema.py
@@ -108,6 +108,11 @@ class SchemaItem(SchemaEventTarget, visitors.Visitable):
"""
return {}
+ def _schema_item_copy(self, schema_item):
+ if 'info' in self.__dict__:
+ schema_item.info = self.info.copy()
+ schema_item.dispatch._update(self.dispatch)
+ return schema_item
class Table(SchemaItem, TableClause):
@@ -718,8 +723,7 @@ class Table(SchemaItem, TableClause):
unique=index.unique,
*[table.c[col] for col in index.columns.keys()],
**index.kwargs)
- table.dispatch._update(self.dispatch)
- return table
+ return self._schema_item_copy(table)
class Column(SchemaItem, ColumnClause):
@@ -1183,12 +1187,10 @@ class Column(SchemaItem, ColumnClause):
server_default=self.server_default,
onupdate=self.onupdate,
server_onupdate=self.server_onupdate,
- info=self.info,
doc=self.doc,
*args
)
- c.dispatch._update(self.dispatch)
- return c
+ return self._schema_item_copy(c)
def _make_proxy(self, selectable, name=None, key=None,
name_is_truncatable=False, **kw):
@@ -1384,8 +1386,7 @@ class ForeignKey(SchemaItem):
link_to_name=self.link_to_name,
match=self.match
)
- fk.dispatch._update(self.dispatch)
- return fk
+ return self._schema_item_copy(fk)
def _get_colspec(self, schema=None):
"""Return a string based 'column specification' for this
@@ -2228,8 +2229,7 @@ class ColumnCollectionConstraint(ColumnCollectionMixin, Constraint):
def copy(self, **kw):
c = self.__class__(name=self.name, deferrable=self.deferrable,
initially=self.initially, *self.columns.keys())
- c.dispatch._update(self.dispatch)
- return c
+ return self._schema_item_copy(c)
def contains_column(self, col):
return self.columns.contains_column(col)
@@ -2310,8 +2310,7 @@ class CheckConstraint(Constraint):
_create_rule=self._create_rule,
table=target_table,
_autoattach=False)
- c.dispatch._update(self.dispatch)
- return c
+ return self._schema_item_copy(c)
class ForeignKeyConstraint(Constraint):
@@ -2480,8 +2479,11 @@ class ForeignKeyConstraint(Constraint):
link_to_name=self.link_to_name,
match=self.match
)
- fkc.dispatch._update(self.dispatch)
- return fkc
+ for self_fk, other_fk in zip(
+ self._elements.values(),
+ fkc._elements.values()):
+ self_fk._schema_item_copy(other_fk)
+ return self._schema_item_copy(fkc)
class PrimaryKeyConstraint(ColumnCollectionConstraint):