--- /dev/null
+.. change::
+ :tags: bug, orm, ext
+ :tickets: 4116
+ :versions: 1.2.0b4
+
+ Fixed bug where the association proxy would inadvertently link itself
+ to an :class:`.AliasedClass` object if it were called first with
+ the :class:`.AliasedClass` as a parent, causing errors upon subsequent
+ usage.
\ No newline at end of file
from .. import exc, orm, util
from ..orm import collections, interfaces
from ..sql import not_, or_
+from .. import inspect
def association_proxy(target_collection, attr, **kw):
def __get__(self, obj, class_):
if self.owning_class is None:
- self.owning_class = class_ and class_ or type(obj)
+ try:
+ insp = inspect(class_)
+ except exc.NoInspectionAvailable:
+ pass
+ else:
+ if hasattr(insp, 'mapper'):
+ self.owning_class = insp.mapper.class_
+
+ if self.owning_class is None:
+ self.owning_class = type(obj)
+
if obj is None:
return self
-from sqlalchemy.testing import eq_, assert_raises
+from sqlalchemy.testing import eq_, assert_raises, is_
import copy
import pickle
from sqlalchemy.testing.schema import Table, Column
from sqlalchemy.testing.mock import Mock, call
from sqlalchemy.testing.assertions import expect_warnings
+from sqlalchemy.ext.declarative import declarative_base
class DictCollection(dict):
)
+class AttributeAccessTest(fixtures.TestBase):
+ def test_resolve_aliased_class(self):
+ Base = declarative_base()
+
+ class A(Base):
+ __tablename__ = 'a'
+ id = Column(Integer, primary_key=True)
+ value = Column(String)
+
+ class B(Base):
+ __tablename__ = 'b'
+ id = Column(Integer, primary_key=True)
+ a_id = Column(Integer, ForeignKey(A.id))
+ a = relationship(A)
+ a_value = association_proxy('a', 'value')
+
+ spec = aliased(B).a_value
+
+ is_(spec.owning_class, B)
+
+ spec = B.a_value
+
+ is_(spec.owning_class, B)
+
+
class InfoTest(fixtures.TestBase):
def test_constructor(self):
assoc = association_proxy('a', 'b', info={'some_assoc': 'some_value'})