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

Accessing AssociationProxy of aliased model breaks it #4116

Closed
sqlalchemy-bot opened this issue Oct 19, 2017 · 12 comments
Closed

Accessing AssociationProxy of aliased model breaks it #4116

sqlalchemy-bot opened this issue Oct 19, 2017 · 12 comments
Labels
bug Something isn't working sqlalchemy.ext extension modules, most of which are ORM related
Milestone

Comments

@sqlalchemy-bot
Copy link
Collaborator

Migrated issue, originally created by Dmytro Starosud (@dima-starosud)

This is using sqlalchemy 1.2.0b3.

When AssociationProxy is first accessed on aliased it leads to setting owning_class to that AliasedClass, which then leads to exceptions inside lib.
Please see details in following code snippet.

        class A(Base):
            __tablename__ = 'a'
            id = Column(Integer, primary_key=True)
            value = Column(String)

        class B(Base):
            __tablename__ = 'b'
            id = Column(Integer, primary_key=True)
            a_id = Column(Integer, ForeignKey(A.id))
            a = relationship(A)
            a_value = association_proxy('a', 'value')

        print(aliased(B).a_value)  # Due to this call line below fails
        print(B(a=A(value=4)).a_value)  # Class object expected, got '<AliasedClass at 0x7f491cbb3048; B>'.

Probably mapper should access AssociationProxy immediately after it's added to the model to trigger owning_class initialization.

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Dmytro Starosud (@dima-starosud):

  • edited description

1 similar comment
@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Dmytro Starosud (@dima-starosud):

  • edited description

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

Probably mapper should access AssociationProxy immediately after it's added to the model to trigger owning_class initialization.

that would be very complicated. I will make it resolve the alias to the real class.

@sqlalchemy-bot
Copy link
Collaborator Author

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • added labels: ext

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • set milestone to "1.1.x"

@sqlalchemy-bot
Copy link
Collaborator Author

Dmytro Starosud (@dima-starosud) wrote:

Thanks @zzzeek

Does Milestone 1.1.x mean we will see this in a version prior to 1.2.0 ?

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

it means I'm cherry-picking it to the 1.1 branch as well which you can see in the above linked gerrit. So the next 1.1 release would also include it.

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

Resolve AliasedClass when determining owning class of association proxy

Fixed bug where the association proxy would inadvertently link itself
to an :class:.AliasedClass object if it were called first with
the :class:.AliasedClass as a parent, causing errors upon subsequent
usage.

Change-Id: I9161bab67766bb75d73ca54d712ad1cad6de40dc
Fixes: #4116

f14a58d

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

Resolve AliasedClass when determining owning class of association proxy

Fixed bug where the association proxy would inadvertently link itself
to an :class:.AliasedClass object if it were called first with
the :class:.AliasedClass as a parent, causing errors upon subsequent
usage.

Change-Id: I9161bab67766bb75d73ca54d712ad1cad6de40dc
Fixes: #4116
(cherry picked from commit f14a58d)

e111940

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot
Copy link
Collaborator Author

Dmytro Starosud (@dima-starosud) wrote:

Thanks @zzzeek !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sqlalchemy.ext extension modules, most of which are ORM related
Projects
None yet
Development

No branches or pull requests

1 participant