Skip to content

Commit

Permalink
Fix Exception: Cannot find reverse relation for model
Browse files Browse the repository at this point in the history
SQLAlchemy 2.0.2 removed the invocation of registry.configure() from
Mapper.iterate_properties causing this problem.

sqlalchemy.orm.registry.configure() was added in 1.4.0b2.

Observed as test failures in:

flask_admin/tests/sqla/test_basic.py
flask_admin/tests/sqla/test_form_rules.py
flask_admin/tests/sqla/test_inlineform.py
  • Loading branch information
cjmayo committed Feb 9, 2023
1 parent 8de618b commit 0948af6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions flask_admin/contrib/sqla/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ def _calculate_mapping_key_pair(self, model, info):

reverse_prop = None

model.registry.configure()
for prop in target_mapper.iterate_properties:
if hasattr(prop, 'direction') and prop.direction.name in ('MANYTOONE', 'MANYTOMANY'):
if issubclass(model, prop.mapper.class_):
Expand Down
1 change: 1 addition & 0 deletions flask_admin/contrib/sqla/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ def _get_model_iterator(self, model=None):
if model is None:
model = self.model

model.registry.configure()
return model._sa_class_manager.mapper.iterate_properties

def _apply_path_joins(self, query, joins, path, inner_join=True):
Expand Down
2 changes: 1 addition & 1 deletion requirements-min.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Flask==1.1.1
itsdangerous==2.0.1
werkzeug==0.16.1
sqlalchemy==1.3.12
sqlalchemy==1.4.0
MarkupSafe==1.1.0
jinja2==2.10.1
Flask-SQLAlchemy==2.1
Expand Down

0 comments on commit 0948af6

Please sign in to comment.