]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- schema.copy() functions will copy dispatch, but only for those events
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 1 Feb 2011 14:26:36 +0000 (09:26 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 1 Feb 2011 14:26:36 +0000 (09:26 -0500)
added with propagate=True.   needs tests
- oracle/fb test schema uses event w/ propagate=True to apply
Sequence to primary key columns with test_needs_autoincrement.
this does actually test the propagate=True flag a bit since it's
needed in the declarative mixin tests where the 'id' column
is copied.

lib/sqlalchemy/schema.py
test/lib/schema.py

index 9cf5c7f14e7edffe4bfb798edc2ffe6525c0e0f5..95f0eb8ecaa2ef85d2605dc83f26da43aec13512 100644 (file)
@@ -470,6 +470,7 @@ class Table(SchemaItem, expression.TableClause):
                   unique=index.unique,
                   *[table.c[col] for col in index.columns.keys()],
                   **index.kwargs)
+        table.dispatch._update(self.dispatch)
         return table
 
 class Column(SchemaItem, expression.ColumnClause):
@@ -862,7 +863,7 @@ class Column(SchemaItem, expression.ColumnClause):
             [c.copy(**kw) for c in self.constraints] + \
             [c.copy(**kw) for c in self.foreign_keys if not c.constraint]
 
-        return Column(
+        c = Column(
                 name=self.name, 
                 type_=self.type, 
                 key = self.key, 
@@ -880,6 +881,8 @@ class Column(SchemaItem, expression.ColumnClause):
                 doc=self.doc,
                 *args
                 )
+        c.dispatch._update(self.dispatch)
+        return c
 
     def _make_proxy(self, selectable, name=None):
         """Create a *proxy* for this column.
@@ -1039,7 +1042,7 @@ class ForeignKey(SchemaItem):
 
         """
 
-        return ForeignKey(
+        fk = ForeignKey(
                 self._get_colspec(schema=schema),
                 use_alter=self.use_alter,
                 name=self.name,
@@ -1049,6 +1052,8 @@ class ForeignKey(SchemaItem):
                 initially=self.initially,
                 link_to_name=self.link_to_name
                 )
+        fk.dispatch._update(self.dispatch)
+        return fk
 
     def _get_colspec(self, schema=None):
         """Return a string based 'column specification' for this :class:`ForeignKey`.
@@ -1579,8 +1584,10 @@ class ColumnCollectionConstraint(ColumnCollectionMixin, Constraint):
         return x in self.columns
 
     def copy(self, **kw):
-        return self.__class__(name=self.name, deferrable=self.deferrable,
+        c = self.__class__(name=self.name, deferrable=self.deferrable,
                               initially=self.initially, *self.columns.keys())
+        c.dispatch._update(self.dispatch)
+        return c
 
     def contains_column(self, col):
         return self.columns.contains_column(col)
@@ -1637,11 +1644,13 @@ class CheckConstraint(Constraint):
     __visit_name__ = property(__visit_name__)
 
     def copy(self, **kw):
-        return CheckConstraint(self.sqltext, 
+        c = CheckConstraint(self.sqltext, 
                                 name=self.name,
                                 initially=self.initially,
                                 deferrable=self.deferrable,
                                 _create_rule=self._create_rule)
+        c.dispatch._update(self.dispatch)
+        return c
 
 class ForeignKeyConstraint(Constraint):
     """A table-level FOREIGN KEY constraint.
@@ -1760,7 +1769,7 @@ class ForeignKeyConstraint(Constraint):
 
 
     def copy(self, **kw):
-        return ForeignKeyConstraint(
+        fkc = ForeignKeyConstraint(
                     [x.parent.name for x in self._elements.values()], 
                     [x._get_colspec(**kw) for x in self._elements.values()], 
                     name=self.name, 
@@ -1771,6 +1780,8 @@ class ForeignKeyConstraint(Constraint):
                     initially=self.initially,
                     link_to_name=self.link_to_name
                 )
+        fkc.dispatch._update(self.dispatch)
+        return fkc
 
 class PrimaryKeyConstraint(ColumnCollectionConstraint):
     """A table-level PRIMARY KEY constraint.
index b4aabfe76cdcca033ea940a9bae6954b57c576e8..0cd38bc647e84f0eeea9e92be1eebb9ea452baba 100644 (file)
@@ -3,7 +3,7 @@ desired state for different backends.
 """
 
 from test.lib import testing
-from sqlalchemy import schema
+from sqlalchemy import schema, event
 
 __all__ = 'Table', 'Column',
 
@@ -64,11 +64,11 @@ def Column(*args, **kw):
     if 'test_needs_autoincrement' in test_opts and \
         kw.get('primary_key', False) and \
         testing.against('firebird', 'oracle'):
-        def add_seq(tbl, c):
+        def add_seq(c, tbl):
             c._init_items(
                 schema.Sequence(_truncate_name(testing.db.dialect, tbl.name + '_' + c.name + '_seq'), optional=True)
             )
-        col._on_table_attach(add_seq)
+        event.listen(col, 'after_parent_attach', add_seq, propagate=True)
     return col
 
 def _truncate_name(dialect, name):