0.5.8
=====
+- sql
+ - The copy() method on Column now supports uninitialized,
+ unnamed Column objects. This allows easy creation of
+ declarative helpers which place common columns on multiple
+ subclasses.
+
- postgresql
- The extract() function, which was slightly improved in
0.5.7, needed a lot more work to generate the correct
This is used in ``Table.tometadata``.
"""
+
+ if self.args:
+ # if not Table initialized
+ args = []
+ for a in self.args:
+ if isinstance(a, Constraint):
+ a = a.copy()
+ args.append(a)
+ else:
+ # if Table initialized
+ args = [c.copy(**kw) for c in self.constraints]
+
return Column(
- self.name,
- self.type,
- self.default,
+ name=self.name,
+ type_=self.type,
key = self.key,
primary_key = self.primary_key,
nullable = self.nullable,
server_default=self.server_default,
onupdate=self.onupdate,
server_onupdate=self.server_onupdate,
- *[c.copy(**kw) for c in self.constraints])
+ *args
+ )
def _make_proxy(self, selectable, name=None):
"""Create a *proxy* for this column.
from sqlalchemy.test.testing import assert_raises, assert_raises_message
import pickle
from sqlalchemy import MetaData
-from sqlalchemy import Integer, String, UniqueConstraint, CheckConstraint, ForeignKey
+from sqlalchemy import Integer, String, UniqueConstraint, CheckConstraint, ForeignKey, Sequence
from sqlalchemy.test.schema import Table
from sqlalchemy.test.schema import Column
import sqlalchemy as tsa
finally:
metadata.drop_all()
-
+ def test_uninitialized_column_copy(self):
+ for col in [
+ Column('foo', String(), nullable=False),
+ Column(Integer(), primary_key=True),
+ Column('bar', Integer(), Sequence('foo_seq'), primary_key=True, key='bar'),
+ Column(Integer(), ForeignKey('bat.blah')),
+ Column('bar', Integer(), ForeignKey('bat.blah'), primary_key=True, key='bar'),
+ ]:
+ c2 = col.copy()
+ for attr in ('name', 'type', 'nullable', 'primary_key', 'key'):
+ eq_(getattr(col, attr), getattr(c2, attr))
+ eq_(len(col.args), len(c2.args))
+ for a1, a2 in zip(col.args, c2.args):
+ if isinstance(a1, ForeignKey):
+ assert a2._colspec == 'bat.blah'
+ elif isinstance(a1, Sequence):
+ assert a2.name == 'foo_seq'
+
def test_dupe_tables(self):
metadata = MetaData()
t1 = Table('table1', metadata, Column('col1', Integer, primary_key=True),