joined eager load innerjoin=True not accommodated by with_polymorphic / joined inh

Issue #3988 resolved
Julien Cigar created an issue

Please see the test case, the error is pretty clear I think :)

Comments (6)

  1. Julien Cigar reporter

    the problem is that SQLAlchemy generates:

    FROM content 
    LEFT OUTER JOIN document ON content.id = document.content_id 
    LEFT OUTER JOIN event ON content.id = event.content_id 
    JOIN country AS country_1 ON country_1.iso = event.country_iso
    

    instead of something like:

    FROM content 
    LEFT OUTER JOIN document ON content.id = document.content_id 
    LEFT OUTER JOIN ( 
        SELECT ... FROM event JOIN country AS country_1 ON country_1.iso = event.country_iso
    ) as event_1 ON event_1.content_id = content.id 
    
  2. Mike Bayer repo owner

    so this is because of your innerjoin=True on that relationship. this is a difficult issue to fix and I don't have any solution for it at the moment. you'd need to be explicit about your innerjoin and either turn it off w/ the with_polymorphic or leave it off by default for now.

  3. Mike Bayer repo owner
    • changed milestone to 1.2

    https://gerrit.sqlalchemy.org/402

    this is for 1.2 at the moment, I'm a little nervous about a 1.1 for this because it will change queries from INNER JOIN to OUTER JOIN, if some app is silently relying on this and is not hitting the bug (because they really are loading only one kind of entity) it could cause a sudden performance issue.

  4. Mike Bayer repo owner

    Demote innerjoin to outerjoin coming from with_polymorphic

    a with_polymorphic, regardless of inheritance type, represents multiple classes. A subclass that wants to joinedload with innerjoin=True needs to be demoted to an outerjoin because the parent entity rows might not be of that type. Looks more intuitive with a joined inheritance load, but applies just as well to single or concrete.

    Change-Id: I4d3d76106ae20032269f8848aad70a8e2f9422f9 Fixes: #3988

    → <<cset 94a089bc2b42>>

  5. Log in to comment