New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load options aren't looking at the superclass #3287
Comments
Michael Bayer (@zzzeek) wrote: likely not a bug, you should be using |
malthe (@malthe) wrote: Actually I failed to reproduce the actual problem in this test case. But there is an issue which is that the alias results in a subselect that lists all the columns in the mapper even though they're not part of the column selection: select a, b from (select a, b, c from foo join bar on ...) Note how |
Michael Bayer (@zzzeek) wrote: it's time to provide a real test case :). Here's a start:
|
Michael Bayer (@zzzeek) wrote: oh, does your test case show this? I can look there. |
Michael Bayer (@zzzeek) wrote: hm, I see a fork of SQLAlchemy there. just give me a quick .py script, thanks. |
malthe (@malthe) wrote: yeah here's the diff: malthe@dcd43de I thought I'd write a test case against the code base. I run the test via: ./sqla_nose.py -sxv -w orm/test_deferred.py But I can try and isolate to a simple .py file. |
Michael Bayer (@zzzeek) wrote: OK, those tests can be helpful when I put the fix in but I need to understand the issue first (I'm fixing something else right now). |
malthe (@malthe) wrote: Here's a snippet that does demonstrate the issue: from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class A(Base):
__tablename__ = 'a'
id = Column(Integer, primary_key=True)
a_name = Column(String)
class B(A):
__tablename__ = 'b'
id = Column(Integer, ForeignKey("a.id"), primary_key=True)
b_name = Column(String)
class C(Base):
__tablename__ = 'c'
id = Column(Integer, primary_key=True)
c_name = Column(String)
b_id = Column("b_id", Integer, ForeignKey("b.id"))
b = relationship(B)
e = create_engine("sqlite://", echo=True)
Base.metadata.create_all(e)
s = Session(e)
b = B(id=1, a_name="foo", b_name="bar")
s.add(b)
c = C(id=1, b_id=b.id, c_name="boo")
s.add(c)
s.flush()
print s.query(C).join(B).options(
contains_eager(C.b).load_only("id")
) Note how |
Michael Bayer (@zzzeek) wrote: ok, so is this the bug?
it isn't looking at the superclass. can we rename this issue then? This is all I'm looking at so far.
|
malthe (@malthe) wrote: I think that's the bug. Let me rename the issue. |
Changes by malthe (@malthe):
|
Michael Bayer (@zzzeek) wrote:
→ b63aae2 |
Michael Bayer (@zzzeek) wrote:
(cherry picked from commit b63aae2) Conflicts: → 11383da |
Changes by Michael Bayer (@zzzeek):
|
malthe (@malthe) wrote: This solves the problem. |
Migrated issue, originally created by malthe (@malthe)
If a query is made on an alias then the
load_only
option fails to exclude properties that are set on a base class of the aliased mapper.This is demonstrated in a test case here: https://github.com/malthe/sqlalchemy/tree/load-only-with-alias-issue
The text was updated successfully, but these errors were encountered: