- changed milestone to 0.9.5
- changed title to select_from() no longer sets _select_from_entity
- changed component to orm
- marked as bug
- marked as critical
select_from() no longer sets _select_from_entity
When using filter_by
to simplify filter
expressions
session.query(User).filter(User.id == 1)
session.query(User).filter_by(id=1)
where filter_by
applies to the last join entity
session.query(User).join(user_group).filter(user_group.c.group_id == 5)
session.query(User).join(user_group).filter_by(group_id=5)
I stumbled on the fact that it does not follow a select_from
(which I expected intuitively):
session.query(User).select_from(user_group).filter(user_group.c.group_id == 5).join(User)
session.query(User).select_from(user_group).filter_by(group_id=5).join(User)
The second one fails. In my concrete case, the primary entity actually had an attribute with the same name. Hence, I ended up with the wrong filter condition (discovering that much later).
Maybe a hint in the documentation of filter_by
and/or select_from
could help so that others don't make the same mistake.
In the long run, I might also suggest to change this behaviour.
Comments (7)
-
repo owner -
reporter Aah, allright, thanks. I first thought it was a bug. But after reading in the docs that
filter_by
applies to the primary query entity or the lastjoin
call, it looked more like intended behaviour.I may have misinterpreted the terminology (does
select_from
reset the primary entity?). Maybe the docs on that can be made more helpful when the bug is fixed. -
repo owner - changed milestone to 0.9.7
-
repo owner - changed status to resolved
- Fixed a regression from 0.9.0 due to
2736
where the :meth:.Query.select_from
method no longer set up the "from entity" of the :class:.Query
object correctly, so that subsequent :meth:.Query.filter_by
or :meth:.Query.join
calls would fail to check the appropriate "from" entity when searching for attributes by string name. fixes#3083
→ <<cset ec40a84d96e4>>
-
repo owner - Fixed a regression from 0.9.0 due to
2736
where the :meth:.Query.select_from
method no longer set up the "from entity" of the :class:.Query
object correctly, so that subsequent :meth:.Query.filter_by
or :meth:.Query.join
calls would fail to check the appropriate "from" entity when searching for attributes by string name. fixes#3083
→ <<cset 87a4ebf8af84>>
- Fixed a regression from 0.9.0 due to
-
repo owner - changed milestone to 0.9.8
-
repo owner - changed milestone to 0.9.7
- Log in to comment
this is a critical regression from 0.8, broken in 04317bd5 due to the change for
#2736. While that ticket is correct, the _select_from_entity attribute was totally forgotten and no tests caught it.Two such tests that should pass are below.