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

fix: change sqla is_relationship for support sqla<=2.0.0 #2357

Closed

Conversation

miettal
Copy link

@miettal miettal commented May 19, 2023

close #2345

@miettal
Copy link
Author

miettal commented Aug 11, 2023

how about this PR? > @flask-admin maintainer

@ericvanular
Copy link

Is it possible to merge this PR? Relationships are not fully usable in SQLA2 currently

Copy link
Contributor

@cjmayo cjmayo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #2332 there is a commit aee829a that adds model.registry.configure(). This is described in https://docs.sqlalchemy.org/en/20/orm/mapping_api.html#sqlalchemy.orm.registry.configure.

I'm no SQLAlchemy expert, only saying that this stopped the test exceptions and looks like it works with the example in the linked issue.

@@ -224,7 +224,8 @@ def is_hybrid_property(model, attr_name):


def is_relationship(attr):
return hasattr(attr, 'property') and hasattr(attr.property, 'direction')
return (hasattr(attr, 'property') and hasattr(attr.property, 'direction') # sqla<2.0.0
or (hasattr(attr, '_is_relationship') and attr._is_relationship)) # sqla>=2.0.0
Copy link
Contributor

@cjmayo cjmayo Oct 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the attributes starting with _ documented?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this is not documented.
Actually I just found _is_relationship when debugging. this is reason why I use _is_relationship.
if there is a solution that documented (model.registry.configure()), the solution is best!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safer I guess anyway, better or best? I found another way #2398. Replacing mapper.iterate_properties with mapper.attrs, which does a check to see if model.registry.configure() has been done. But that does seem to have been around for a while, why iterate_properties was used in the first place I do not know.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not familiar with SQLAlchemy, a just user of flask-admin, sqlalchemy. So I follow mantainer's decistion. ;)

@samuelhwilliams
Copy link
Contributor

@cjmayo do we still need this for sqlalchemy 1/2 compatibility?

@cjmayo
Copy link
Contributor

cjmayo commented Aug 7, 2024

I think the merged #2398 has addressed this problem.
I still wouldn't know if that was the best of the 3 solutions we came up with.
Hopefully it will get more testers now.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

ForeignKey column is not listed in view.
4 participants