Skip to content

Commit

Permalink
add compatibility sqla1.4 (is_already_joined) + add CompoundSelect to…
Browse files Browse the repository at this point in the history
… qfilter
  • Loading branch information
jacquesfize committed Dec 14, 2023
1 parent ffab504 commit 21adb12
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/utils_flask_sqla/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sqlalchemy.sql.expression import BooleanClauseList, BinaryExpression
from flask_sqlalchemy.model import DefaultMeta
from sqlalchemy.sql import select, Select
from sqlalchemy.sql import select, Select, CompoundSelect

AUTHORIZED_WHERECLAUSE_TYPES = [bool, BooleanClauseList, BinaryExpression]

Expand Down Expand Up @@ -86,7 +86,7 @@ def _(*args, **kwargs):
kwargs["query"] = query
result = method(*args, **kwargs)

if is_query and not isinstance(result, Select):
if is_query and not (isinstance(result, Select) or isinstance(result, CompoundSelect)):
raise ValueError("Your method must return a SQLAlchemy Select object ")

Check warning on line 90 in src/utils_flask_sqla/models.py

View check run for this annotation

Codecov / codecov/patch

src/utils_flask_sqla/models.py#L90

Added line #L90 was not covered by tests

if not is_query and not is_whereclause_compatible(result):
Expand Down
2 changes: 1 addition & 1 deletion src/utils_flask_sqla/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def is_already_joined(my_class, query):
query: SQLAlchemy query
return boolean
"""
for visitor in visitors.iterate(query.statement):
for visitor in visitors.iterate(query):
# Checking for `.join(Parent.child)` clauses
if visitor.__visit_name__ == "binary":
for vis in visitors.iterate(visitor):
Expand Down

0 comments on commit 21adb12

Please sign in to comment.