[ticket:1531]
- relation() with uselist=False will emit a warning when
- an eager load locates more than one valid value for the row,
- typically due to primaryjoin/secondaryjoin conditions which
- aren't appropriate for LEFT OUTER JOIN. [ticket:1643]
+ an eager or lazy load locates more than one valid value for
+ the row. This may be due to primaryjoin/secondaryjoin
+ conditions which aren't appropriate for an eager LEFT OUTER
+ JOIN or for other conditions. [ticket:1643]
- an explicit check occurs when a synonym() is used with
map_column=True, when a ColumnProperty (deferred or otherwise)
if strategy.uselist:
return result
else:
- if result:
+ l = len(result)
+ if l:
+ if l > 1:
+ util.warn(
+ "Multiple rows returned with "
+ "uselist=False for lazily-loaded attribute '%s' " % prop)
+
return result[0]
else:
return None
l = q.filter(s.c.u2_id==User.id).order_by(User.id).distinct().all()
eq_(self.static.user_all_result, l)
+ @testing.resolve_artifact_names
+ def test_uselist_false_warning(self):
+ """test that multiple rows received by a uselist=False raises a warning."""
+
+ mapper(User, users, properties={
+ 'order':relation(Order, uselist=False)
+ })
+ mapper(Order, orders)
+ s = create_session()
+ u1 = s.query(User).filter(User.id==7).one()
+ assert_raises(sa.exc.SAWarning, getattr, u1, 'order')
+
@testing.resolve_artifact_names
def test_one_to_many_scalar(self):
mapper(User, users, properties = dict(
order_by=pages.c.pagename)),
'currentversion': relation(
PageVersion,
- foreign_keys=[pages.c.current_version],
+ uselist=False,
primaryjoin=sa.and_(
pages.c.jobno==pageversions.c.jobno,
pages.c.pagename==pageversions.c.pagename,
order_by=pagecomments.c.comment_id))})
@testing.resolve_artifact_names
- def testbasic(self):
+ def test_basic(self):
"""A combination of complicated join conditions with post_update."""
j1 = Job(jobno=u'somejob')