Skip to content
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

noload for scalar attributes behaves like lazyload #3510

Closed
sqlalchemy-bot opened this issue Aug 11, 2015 · 11 comments
Closed

noload for scalar attributes behaves like lazyload #3510

sqlalchemy-bot opened this issue Aug 11, 2015 · 11 comments
Labels
bug Something isn't working high priority orm
Milestone

Comments

@sqlalchemy-bot
Copy link
Collaborator

Migrated issue, originally created by Adrian (@thiefmaster)

I would expect the last print in this script to show None, but as of 1.0.x it shows a C object (which is lazy-loaded).

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()


class A(Base):
    __tablename__ = 'test_a'

    id = Column(Integer, primary_key=True)


class B(Base):
    __tablename__ = 'test_b'

    id = Column(Integer, primary_key=True)
    a_id = Column(Integer, ForeignKey('test_a.id'))
    c_id = Column(Integer, ForeignKey('test_c.id'))
    a = relationship('A', backref=backref('b'))
    c = relationship('C', backref=backref('b'))


class C(Base):
    __tablename__ = 'test_c'

    id = Column(Integer, primary_key=True)


e = create_engine('sqlite:///:memory:', echo=True)
Base.metadata.create_all(e)

s = Session(e)
s.add(B(a=A(), c=C()))
s.commit()

a = s.query(A).options(joinedload('b').noload('c')).all()
print a[0]
print a[0].b[0]
print a[0].b[0].c

Script + full output: https://gist.github.com/ThiefMaster/d6c16d26c77507612b0d

@sqlalchemy-bot
Copy link
Collaborator Author

Alex Grönholm (@agronholm) wrote:

I should add that the above script works fine on 0.9.9 but is broken on 1.0.0.

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

regression from #3061, initialize() no longer sets a value and noload relies on initialize() to place an empty value

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • added labels: high priority

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • set milestone to "1.0.9"

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • changed title from "noload behaves like lazyload" to "noload for scalar attributes behaves like lazyload"

@sqlalchemy-bot
Copy link
Collaborator Author

Adrian (@thiefmaster) wrote:

kind of unrelated, but a "strict" noload strategy that fails with an exception instead of returning None would be nice - i guess when explicitly deciding not to load a relationship you expect your code not to access it, so if it does something is likely wrong, and with an exception you'd notice it easily

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

you've posted a perfect bug report, don't spoil it ;)

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

here is the code for that: https://groups.google.com/forum/#!topic/sqlalchemy/X_wA8K97smE user failed to post a PR, please do so.

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

5198b1d 7f35489 thanks for reporting!

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot
Copy link
Collaborator Author

Adrian (@thiefmaster) wrote:

thanks for the link to the mailing list! here's a PR: zzzeek/sqlalchemy#193 (sorry, I prefer github ;))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high priority orm
Projects
None yet
Development

No branches or pull requests

1 participant