Skip to content

Commit

Permalink
Call property mapper to materialize lazy attrs
Browse files Browse the repository at this point in the history
A Relationship property from a mapper may not have all expected
attributes available immediately. Calling the `prop.mapper` property
will cause these missing attributes to materialize.
  • Loading branch information
whiskeyriver committed May 17, 2023
1 parent 896fca6 commit 18adec9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions flask_admin/contrib/sqla/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,13 @@ def _calculate_mapping_key_pair(self, model, info):
reverse_prop = None

for prop in target_mapper.iterate_properties:
try:
# Loading the mapper property will populate a lazy direction
# attribute
prop.mapper
except AttributeError:
continue

if hasattr(prop, 'direction') and prop.direction.name in ('MANYTOONE', 'MANYTOMANY'):
if issubclass(model, prop.mapper.class_):
reverse_prop = prop
Expand Down

0 comments on commit 18adec9

Please sign in to comment.