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.

Using SQLAlchemy 1.4 requires SQLAlchemy-Utils >= 0.37.0 else:
ImportError: cannot import name '_ColumnEntity' from 'sqlalchemy.orm.query'

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 ddf6024
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
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
4 changes: 2 additions & 2 deletions 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 All @@ -16,7 +16,7 @@ shapely==1.5.9
geoalchemy2==0.6.3
psycopg2==2.8.4
sqlalchemy-citext==1.5-0
sqlalchemy-utils==0.36.6
sqlalchemy-utils==0.37.0
azure-storage-blob==1.4.0
arrow==0.13.2
colour==0.1.5
Expand Down

0 comments on commit ddf6024

Please sign in to comment.