Commit b71634c3 authored by Jacob Magnusson's avatar Jacob Magnusson

Fix regression with late-evaluation relationships no longer working for filters

Regression was introduced in 47080aeb (PR #1348) where `is_hybrid_property` was changed to support remote hybrid properties. When lambdas were encountered in the iteration they were passed as-is to the function `get_hybrid_properties`, which in turn threw the exception `sqlalchemy.exc.NoInspectionAvailable: No inspection system is available for object of type <class 'function'>`.

Test has been updated to ensure that flask-admin will continue to support lambdas as a relationship’s first argument.
parent 226f2360
import types
from sqlalchemy import tuple_, or_, and_, inspect from sqlalchemy import tuple_, or_, and_, inspect
from sqlalchemy.ext.declarative.clsregistry import _class_resolver from sqlalchemy.ext.declarative.clsregistry import _class_resolver
from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.ext.hybrid import hybrid_property
...@@ -201,6 +203,8 @@ def is_hybrid_property(model, attr_name): ...@@ -201,6 +203,8 @@ def is_hybrid_property(model, attr_name):
last_model = attr.property.argument last_model = attr.property.argument
if isinstance(last_model, _class_resolver): if isinstance(last_model, _class_resolver):
last_model = model._decl_class_registry[last_model.arg] last_model = model._decl_class_registry[last_model.arg]
elif isinstance(last_model, types.FunctionType):
last_model = last_model()
last_name = names[-1] last_name = names[-1]
return last_name in get_hybrid_properties(last_model) return last_name in get_hybrid_properties(last_model)
else: else:
......
...@@ -84,7 +84,7 @@ def create_models(db): ...@@ -84,7 +84,7 @@ def create_models(db):
# Relation # Relation
model1_id = db.Column(db.Integer, db.ForeignKey(Model1.id)) model1_id = db.Column(db.Integer, db.ForeignKey(Model1.id))
model1 = db.relationship(Model1, backref='model2') model1 = db.relationship(lambda: Model1, backref='model2')
db.create_all() db.create_all()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment