Skip to content

Commit

Permalink
fixup! add join check function
Browse files Browse the repository at this point in the history
  • Loading branch information
bouttier committed Nov 10, 2023
1 parent 907cd22 commit 661a3d8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/utils_flask_sqla/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __enter__(self):
copyfileobj(response, remote_file)
return remote_file_path


def is_already_joined(my_class, query):
"""
Check if the given class is already present is the current query
Expand All @@ -44,16 +45,16 @@ def is_already_joined(my_class, query):
"""
for visitor in visitors.iterate(query.statement):
# Checking for `.join(Parent.child)` clauses
if visitor.__visit_name__ == 'binary':
if visitor.__visit_name__ == "binary":
for vis in visitors.iterate(visitor):
# Visitor might not have table attribute
with suppress(AttributeError):
# Verify if already present based on table name
if my_class.__table__.fullname == vis.table.fullname:
return True
# Checking for `.join(Child)` clauses
if visitor.__visit_name__ == 'table':
# Visitor might be of ColumnCollection or so,
if visitor.__visit_name__ == "table":
# Visitor might be of ColumnCollection or so,
# which cannot be compared to model
with suppress(TypeError):
if my_class == visitor.entity_namespace:
Expand All @@ -63,4 +64,4 @@ def is_already_joined(my_class, query):
with suppress(AttributeError):
if my_class.__table__.fullname == visitor.table.fullname:
return True
return False
return False

0 comments on commit 661a3d8

Please sign in to comment.