--- /dev/null
+.. change::
+ :tags: bug, orm
+ :tickets: 4729
+
+ Fixed bug where the :attr:`.Mapper.all_orm_descriptors` accessor would
+ return an entry for the :class:`.Mapper` itself under the declarative
+ ``__mapper___`` key, when this is not a descriptor. The ``.is_attribute``
+ flag that's present on all :class:`.InspectionAttr` objects is now
+ consulted, which has also been modified to be ``True`` for an association
+ proxy, as it was erroneously set to False for this object.
class AssociationProxy(interfaces.InspectionAttrInfo):
"""A descriptor that presents a read/write view of an object attribute."""
- is_attribute = False
+ is_attribute = True
extension_type = ASSOCIATION_PROXY
def __init__(
for key in set(supercls.__dict__).difference(exclude):
exclude.add(key)
val = supercls.__dict__[key]
- if isinstance(val, interfaces.InspectionAttr):
+ if (
+ isinstance(val, interfaces.InspectionAttr)
+ and val.is_attribute
+ ):
yield key, val
def _get_class_attr_mro(self, key, default=None):
eq_(Foo.__mapper__.CHECK, True)
+ def test_no_change_to_all_descriptors(self):
+ base = decl.declarative_base()
+
+ class Foo(base):
+ __tablename__ = "foo"
+ id = Column(Integer, primary_key=True)
+
+ eq_(Foo.__mapper__.all_orm_descriptors.keys(), ["id"])
+
def test_oops(self):
with testing.expect_warnings(
from sqlalchemy.orm import synonym
from sqlalchemy.orm.attributes import instance_state
from sqlalchemy.orm.attributes import NO_VALUE
+from sqlalchemy.orm.base import InspectionAttr
from sqlalchemy.orm.util import identity_key
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import eq_
assert "name" in u1.__dict__
def test_attrs_props_prop_added_after_configure(self):
- class AnonClass(object):
+ class Thing(InspectionAttr):
pass
+ class AnonClass(object):
+ __foo__ = "bar"
+ __bat__ = Thing()
+
from sqlalchemy.orm import mapper, column_property
from sqlalchemy.ext.hybrid import hybrid_property