]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixed bug where using an annotation such as :func:`.remote` or
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 8 Oct 2013 23:47:13 +0000 (19:47 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 8 Oct 2013 23:47:13 +0000 (19:47 -0400)
: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]

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/sql/elements.py
test/sql/test_selectable.py

index 9e65389ca11cde60441526ba4d0add7595fd2afe..87dbc8f93a54dbed3cd624f13d13f4e942baf5b7 100644 (file)
 .. changelog::
     :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
index 73a8a0b82cb1dcc49ce5c4d5d5b2b78f4af7f5d0..2688ef103df55952cd2d0f555ecb3fd4e5d2aa41 100644 (file)
@@ -2466,7 +2466,7 @@ class AnnotatedColumnElement(Annotated):
     def __init__(self, element, values):
         Annotated.__init__(self, element, values)
         ColumnElement.comparator._reset(self)
-        for attr in ('name', 'key'):
+        for attr in ('name', 'key', 'table'):
             if self.__dict__.get(attr, False) is None:
                 self.__dict__.pop(attr)
 
@@ -2480,6 +2480,11 @@ class AnnotatedColumnElement(Annotated):
         """pull 'name' from parent, if not present"""
         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"""
index df174fb25511ce7b0cf2cbc670e6f3d1e5a42a2f..87a226782566f7bf11abc54401c475646394bcc4 100644 (file)
@@ -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,
@@ -1460,6 +1461,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):