summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES6
-rw-r--r--lib/sqlalchemy/schema.py2
-rw-r--r--test/sql/test_metadata.py78
3 files changed, 85 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index 6ba873844..3c59cf3db 100644
--- a/CHANGES
+++ b/CHANGES
@@ -30,6 +30,12 @@ CHANGES
- Added explicit check for when Column .name
is assigned as blank string [ticket:2140]
+ - Fixed bug whereby if FetchedValue was passed
+ to column server_onupdate, it would not
+ have its parent "column" assigned, added
+ test coverage for all column default assignment
+ patterns. [ticket:2147] also in 0.6.8
+
- postgresql
- Fixed the psycopg2_version parsing in the
psycopg2 dialect.
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py
index bff3e8d63..72516acd6 100644
--- a/lib/sqlalchemy/schema.py
+++ b/lib/sqlalchemy/schema.py
@@ -836,7 +836,7 @@ class Column(SchemaItem, expression.ColumnClause):
if self.server_onupdate is not None:
if isinstance(self.server_onupdate, FetchedValue):
- args.append(self.server_default)
+ args.append(self.server_onupdate)
else:
args.append(DefaultClause(self.server_onupdate,
for_update=True))
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py
index 87d8ae516..ea18229de 100644
--- a/test/sql/test_metadata.py
+++ b/test/sql/test_metadata.py
@@ -979,6 +979,84 @@ class ColumnDefinitionTest(AssertsCompiledSQL, fixtures.TestBase):
getattr, select([t1.select().alias()]), 'c'
)
+class ColumnDefaultsTest(fixtures.TestBase):
+ """test assignment of default fixures to columns"""
+
+ def _fixture(self, *arg, **kw):
+ return Column('x', Integer, *arg, **kw)
+
+ def test_server_default_positional(self):
+ target = schema.DefaultClause('y')
+ c = self._fixture(target)
+ assert c.server_default is target
+ assert target.column is c
+
+ def test_server_default_keyword_as_schemaitem(self):
+ target = schema.DefaultClause('y')
+ c = self._fixture(server_default=target)
+ assert c.server_default is target
+ assert target.column is c
+
+ def test_server_default_keyword_as_clause(self):
+ target = 'y'
+ c = self._fixture(server_default=target)
+ assert c.server_default.arg == target
+ assert c.server_default.column is c
+
+ def test_server_default_onupdate_positional(self):
+ target = schema.DefaultClause('y', for_update=True)
+ c = self._fixture(target)
+ assert c.server_onupdate is target
+ assert target.column is c
+
+ def test_server_default_onupdate_keyword_as_schemaitem(self):
+ target = schema.DefaultClause('y', for_update=True)
+ c = self._fixture(server_onupdate=target)
+ assert c.server_onupdate is target
+ assert target.column is c
+
+ def test_server_default_onupdate_keyword_as_clause(self):
+ target = 'y'
+ c = self._fixture(server_onupdate=target)
+ assert c.server_onupdate.arg == target
+ assert c.server_onupdate.column is c
+
+ def test_column_default_positional(self):
+ target = schema.ColumnDefault('y')
+ c = self._fixture(target)
+ assert c.default is target
+ assert target.column is c
+
+ def test_column_default_keyword_as_schemaitem(self):
+ target = schema.ColumnDefault('y')
+ c = self._fixture(default=target)
+ assert c.default is target
+ assert target.column is c
+
+ def test_column_default_keyword_as_clause(self):
+ target = 'y'
+ c = self._fixture(default=target)
+ assert c.default.arg == target
+ assert c.default.column is c
+
+ def test_column_default_onupdate_positional(self):
+ target = schema.ColumnDefault('y', for_update=True)
+ c = self._fixture(target)
+ assert c.onupdate is target
+ assert target.column is c
+
+ def test_column_default_onupdate_keyword_as_schemaitem(self):
+ target = schema.ColumnDefault('y', for_update=True)
+ c = self._fixture(onupdate=target)
+ assert c.onupdate is target
+ assert target.column is c
+
+ def test_column_default_onupdate_keyword_as_clause(self):
+ target = 'y'
+ c = self._fixture(onupdate=target)
+ assert c.onupdate.arg == target
+ assert c.onupdate.column is c
+
class ColumnOptionsTest(fixtures.TestBase):
def test_default_generators(self):