On 10/29/15 7:54 PM, Jonathan Vanasco wrote:
> 
> 
> The difference is between these 2 forms:
> 
> [(f.id, f.bar_id) for f in
> session.query(Foo).options(joinedload('bar')).order_by(Foo.id.desc()).offset(0).limit(100).all()]
> [(f.id, f.bar_id) for f in
> session.query(Foo).options(contains_eager('bar')).order_by(Foo.id.desc()).offset(0).limit(100).all()]


you wouldn't typically want to specify contains_eager('bar') if the SQL
has no JOIN in it, which you'd do with query.join().


> 
> In my actual codebase, something drops the 26 items from `joinedload` to
> only contain the 3 that have a `bar` on `contains_eager`.
> 
> I'd love to figure out WTF is doing that, because it seems to be some
> bug or gotcha. The "fix" is simple -- use `joinedload` like I intended.
> 
> 
>     eager loading takes what it can find at result processing time but
>     doesn't assume anything is there.  it looks for the columns it expects.
> 
> 
> but if the colums aren't there, shouldn't there be an error like
> "`contains_eager` called, but query does not contain any usable columns" ?

There's kind of a "firewall" between the "I'm writing the SQL" side of
the ORM and the "I'm fetching rows" side of the ORM.  This is a long
standing behavior to allow any result set to be passed in to a Query and
to get objects back from it, part of the original idea that "you'll
never be prevented from writing straight SQL" philosophy of SQLAlchemy.
  So the joined eager load system, as well as the loaders for plain
columns, are all agnostic of whether or not their column is there; they
all check for it based on cursor.description up front and if their
column isn't there, they assume they'll be a deferred/lazy load later on.



> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to