decorators on child classes that aren't broken by a
@compiles decorator on the base class.
+ - Declarative will raise an informative error message
+ if a non-mapped class attribute is referenced in the
+ string-based relationship() arguments.
+
0.6beta3
========
mapper = class_mapper(self.cls, compile=False)
if mapper:
- prop = mapper.get_property(key)
- if not isinstance(prop, ColumnProperty):
+ prop = mapper.get_property(key, raiseerr=False)
+ if prop is None:
+ raise exceptions.InvalidRequestError(
+ "Class %r does not have a mapped column named %r"
+ % (self.cls, key))
+ elif not isinstance(prop, ColumnProperty):
raise exceptions.InvalidRequestError(
"Property %r is not an instance of"
" ColumnProperty (i.e. does not correspond"
rel = relationship("User", primaryjoin="User.addresses==Foo.id")
assert_raises_message(exc.InvalidRequestError, "'addresses' is not an instance of ColumnProperty", compile_mappers)
+ def test_string_dependency_resolution_two(self):
+ class User(Base, ComparableEntity):
+ __tablename__ = 'users'
+ id = Column(Integer, primary_key=True, test_needs_autoincrement=True)
+ name = Column(String(50))
+ addresses = relationship("Address", order_by="desc(Address.email)",
+ primaryjoin="User.id==Address.user_id", foreign_keys="[Address.user_id]",
+ backref=backref('user', primaryjoin="User.id==Address.user_id", foreign_keys="[Address.user_id]")
+ )
+
+
+ class Bar(Base, ComparableEntity):
+ __tablename__ = 'bar'
+ id = Column(Integer, primary_key=True)
+ rel = relationship("User", primaryjoin="User.id==Bar.__table__.id")
+ assert_raises_message(exc.InvalidRequestError, "does not have a mapped column named '__table__'", compile_mappers)
+
def test_string_dependency_resolution_no_magic(self):
"""test that full tinkery expressions work as written"""