diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-10-08 19:47:13 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-10-08 19:49:09 -0400 |
commit | 79f55eb20bf3b65bf0663cf96de96c68f8804399 (patch) | |
tree | d3ebf0486a0d4bf0681e077a5a3ea7bdb4dbc87f | |
parent | c1a69ab841e728061dd890dd02e6ce6be2970473 (diff) | |
download | sqlalchemy-79f55eb20bf3b65bf0663cf96de96c68f8804399.tar.gz |
Fixed bug where using an annotation such as :func:`.remote` or
:func:`.foreign` on a :class:`.Column` before association with a parent
:class:`.Table` could produce issues related to the parent table not
rendering within joins, due to the inherent copy operation performed
by an annotation. [ticket:2813]
Conflicts:
lib/sqlalchemy/sql/elements.py
-rw-r--r-- | doc/build/changelog/changelog_08.rst | 11 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/util.py | 7 | ||||
-rw-r--r-- | test/sql/test_selectable.py | 7 |
3 files changed, 24 insertions, 1 deletions
diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index 54e10ec64..70521ecbf 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -11,6 +11,17 @@ :version: 0.8.3 .. change:: + :tags: bug, orm + :tickets: 2813 + :versions: 0.9.0 + + Fixed bug where using an annotation such as :func:`.remote` or + :func:`.foreign` on a :class:`.Column` before association with a parent + :class:`.Table` could produce issues related to the parent table not + rendering within joins, due to the inherent copy operation performed + by an annotation. + + .. change:: :tags: bug, sql :tickets: 2831 diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 61730f1f0..fdc5bb372 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -497,7 +497,7 @@ class Annotated(object): class AnnotatedColumnElement(Annotated): def __init__(self, element, values): Annotated.__init__(self, element, values) - for attr in ('name', 'key'): + for attr in ('name', 'key', 'table'): if self.__dict__.get(attr, False) is None: self.__dict__.pop(attr) @@ -507,6 +507,11 @@ class AnnotatedColumnElement(Annotated): return self._Annotated__element.name @util.memoized_property + def table(self): + """pull 'table' from parent, if not present""" + return self._Annotated__element.table + + @util.memoized_property def key(self): """pull 'key' from parent, if not present""" return self._Annotated__element.key diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index 03357eb74..649490ef3 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -10,6 +10,7 @@ from sqlalchemy.sql import util as sql_util, visitors, expression from sqlalchemy import exc from sqlalchemy.sql import table, column, null from sqlalchemy import util +from sqlalchemy.schema import Column, Table, MetaData metadata = MetaData() table1 = Table('table1', metadata, @@ -1380,6 +1381,12 @@ class AnnotationsTest(fixtures.TestBase): c1.name = 'somename' eq_(c1_a.name, 'somename') + def test_late_table_add(self): + c1 = Column("foo", Integer) + c1_a = c1._annotate({"foo": "bar"}) + t = Table('t', MetaData(), c1) + is_(c1_a.table, t) + def test_custom_constructions(self): from sqlalchemy.schema import Column class MyColumn(Column): |