From 49739b8632c2dbe5cc78cdfcbaae62c932007c68 Mon Sep 17 00:00:00 2001 From: BryanLee Date: Mon, 21 Nov 2022 11:06:48 +0800 Subject: [PATCH] fix: Q.resolve compatibility problem --- Pipfile | 1 + fastapi_esql/__init__.py | 2 +- fastapi_esql/utils/sqlizer.py | 9 +++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Pipfile b/Pipfile index 331b90b..96a9494 100644 --- a/Pipfile +++ b/Pipfile @@ -13,6 +13,7 @@ cryptography = "*" faker = "*" fastapi = "*" uvicorn = "*" +tortoise-orm = "*" [requires] python_version = "3.7" diff --git a/fastapi_esql/__init__.py b/fastapi_esql/__init__.py index d7d7f2a..eedfd38 100644 --- a/fastapi_esql/__init__.py +++ b/fastapi_esql/__init__.py @@ -17,7 +17,7 @@ timing, ) -__version__ = "0.0.5" +__version__ = "0.0.6" __all__ = [ "QsParsingError", diff --git a/fastapi_esql/utils/sqlizer.py b/fastapi_esql/utils/sqlizer.py index 686688f..80da85a 100644 --- a/fastapi_esql/utils/sqlizer.py +++ b/fastapi_esql/utils/sqlizer.py @@ -2,7 +2,7 @@ from json import dumps from typing import Any, Dict, List, Optional, Union -from tortoise import Model +from tortoise import Model, __version__ from tortoise.queryset import Q from tortoise.query_utils import QueryModifier @@ -68,7 +68,12 @@ def resolve_wheres( modifier = QueryModifier() for q in qs: - modifier &= q.resolve(model, model._meta.basetable) + # NOTE method `Q.resolve` changed since V0.18.0 + # https://github.com/tortoise/tortoise-orm/commit/37178e175bc12bc4767b93142dab0209f9240c55 + if __version__ >= "0.18.0": + modifier &= q.resolve(model, model._meta.basetable) + else: + modifier &= q.resolve(model, {}, {}, model._meta.basetable) return modifier.where_criterion.get_sql(quote_char="`") @classmethod