On 10/29/15 6:50 PM, Jonathan Vanasco wrote:
> I've spent an hour trying to reproduce this bug and can't.   I'm hoping
> someone can suggest what might be going on so I can make this
> reproducable for a bug report
> 
> I have 2 classes:
> 
>     class Foo(Base):
>         __tablename__ = 'foo'
>         id = Column(Integer, primary_key=True)
>         bar_id = Column(Integer, ForeignKey("bar.id"), nullable=True)
> 
>     class Bar(Base):
>         __tablename__ = 'bar'
>         id = Column(Integer, primary_key=True)
>         is_x = Column(Boolean, nullable=True)
> 
>     # monkeypatched relationship
>     Foo.bar = sqlalchemy.orm.relationship("Bar",
> primaryjoin=sqlalchemy.and_(Foo.bar_id == Bar.id, Bar.is_x.op("IS
> NOT")(True)))

i dont have an immediate answer, though i wonder why you aren't using
~Bar.is_x.is(True) for that "IS NOT"...

> 
> The not-reproducable problem is the following:
> 
> If I pass in a `contains_eager` clause WITHOUT doing a join, I end up
> limited to all the Foo's with a Bar.
> 
>    
> session.query(Foo).options(contains_eager('bar')).order_by(Foo.id.desc()).offset(0).limit(100).all()

why would contains_eager("bar") do anything here if you aren't joining
out to Bar ?

> 
> However if I join, or do a joinedload, I correctly end up with all the
> Foos (their Bar status is irrelevant)

mixing joinedload and contains_eager?  youd be using join()....

> 
> The generated SQL looks fine 00 it seems that there's some
> post-processing bit in sqlalchemy that is dropping this.
> 
> My production version has several dozen attributes and class functions.
>  Testing one-by-one isn't working well.
> 
> Does anyone have hints on a better way to troubleshoot this?
> 
> Also, shouldn't `contains_eager` raise some sort of error if you don't
> actually contain that object?

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.




> 
> 
> 
> 
> 
> 
> 
> -- 
> 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