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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flask_admin/contrib/sqla/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def convert(self, model, mapper, name, prop, field_args, hidden_pk):
kwargs['validators'] = list(kwargs['validators'])

# Check if it is relation or property
if hasattr(prop, 'direction') or is_association_proxy(prop):
if is_relationship(prop) or is_association_proxy(prop):
property_is_association_proxy = is_association_proxy(prop)
if property_is_association_proxy:
if not hasattr(prop.remote_attr, 'prop'):
Expand Down
3 changes: 2 additions & 1 deletion flask_admin/contrib/sqla/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. ;)



def is_association_proxy(attr):
Expand Down