mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-06-03 06:19:59 -04:00
- Fixed column.copy() to copy defaults and onupdates.
[ticket:1373]
This commit is contained in:
@@ -413,6 +413,9 @@ CHANGES
|
||||
is old stuff. [ticket:1486]
|
||||
|
||||
- sql
|
||||
- Fixed column.copy() to copy defaults and onupdates.
|
||||
[ticket:1373]
|
||||
|
||||
- Fixed a bug in extract() introduced in 0.5.4 whereby
|
||||
the string "field" argument was getting treated as a
|
||||
ClauseElement, causing various errors within more
|
||||
|
||||
@@ -782,6 +782,10 @@ class Column(SchemaItem, expression.ColumnClause):
|
||||
quote=self.quote,
|
||||
index=self.index,
|
||||
autoincrement=self.autoincrement,
|
||||
default=self.default,
|
||||
server_default=self.server_default,
|
||||
onupdate=self.onupdate,
|
||||
server_onupdate=self.server_onupdate,
|
||||
*[c.copy(**kw) for c in self.constraints])
|
||||
|
||||
def _make_proxy(self, selectable, name=None):
|
||||
|
||||
@@ -631,15 +631,9 @@ class ComparesTables(object):
|
||||
eq_(c.type.length, reflected_c.type.length)
|
||||
|
||||
eq_(set([f.column.name for f in c.foreign_keys]), set([f.column.name for f in reflected_c.foreign_keys]))
|
||||
if c.default:
|
||||
if c.server_default:
|
||||
assert isinstance(reflected_c.server_default,
|
||||
schema.FetchedValue)
|
||||
elif against(('mysql', '<', (5, 0))):
|
||||
# ignore reflection of bogus db-generated DefaultClause()
|
||||
pass
|
||||
elif not c.primary_key or not against('postgresql', 'mssql'):
|
||||
#print repr(c)
|
||||
assert reflected_c.default is None, reflected_c.default
|
||||
|
||||
assert len(table.primary_key) == len(reflected_table.primary_key)
|
||||
for c in table.primary_key:
|
||||
|
||||
@@ -46,6 +46,8 @@ class MetaDataTest(TestBase, ComparesTables):
|
||||
table = Table('mytable', meta,
|
||||
Column('myid', Integer, primary_key=True),
|
||||
Column('name', String(40), nullable=True),
|
||||
Column('foo', String(40), nullable=False, server_default='x', server_onupdate='q'),
|
||||
Column('bar', String(40), nullable=False, default='y', onupdate='z'),
|
||||
Column('description', String(30), CheckConstraint("description='hi'")),
|
||||
UniqueConstraint('name'),
|
||||
test_needs_fk=True,
|
||||
@@ -83,7 +85,7 @@ class MetaDataTest(TestBase, ComparesTables):
|
||||
|
||||
meta.create_all(testing.db)
|
||||
try:
|
||||
for test, has_constraints in ((test_to_metadata, True), (test_pickle, True),(test_pickle_via_reflect, False)):
|
||||
for test, has_constraints, reflect in ((test_to_metadata, True, False), (test_pickle, True, False),(test_pickle_via_reflect, False, True)):
|
||||
table_c, table2_c = test()
|
||||
self.assert_tables_equal(table, table_c)
|
||||
self.assert_tables_equal(table2, table2_c)
|
||||
@@ -92,7 +94,13 @@ class MetaDataTest(TestBase, ComparesTables):
|
||||
assert table.primary_key is not table_c.primary_key
|
||||
assert list(table2_c.c.myid.foreign_keys)[0].column is table_c.c.myid
|
||||
assert list(table2_c.c.myid.foreign_keys)[0].column is not table.c.myid
|
||||
|
||||
assert str(table_c.c.foo.server_default.arg) == 'x'
|
||||
|
||||
if not reflect:
|
||||
assert str(table_c.c.foo.server_onupdate.arg) == 'q'
|
||||
assert str(table_c.c.bar.default.arg) == 'y'
|
||||
assert getattr(table_c.c.bar.onupdate.arg, 'arg', table_c.c.bar.onupdate.arg) == 'z'
|
||||
|
||||
# constraints dont get reflected for any dialect right now
|
||||
if has_constraints:
|
||||
for c in table_c.c.description.constraints:
|
||||
|
||||
Reference in New Issue
Block a user