diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d9484b4b2..fabf07836 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,12 @@ Changelog 0.22 ==== +0.22.2 (unreleased) +------ +Fixed +^^^^^ +- Fix bug related to `Connector.div` in combined expressions. (#1794) + 0.22.1 ------ Fixed diff --git a/tortoise/expressions.py b/tortoise/expressions.py index ebc12a83b..b1b0e180a 100644 --- a/tortoise/expressions.py +++ b/tortoise/expressions.py @@ -3,7 +3,7 @@ import operator from dataclasses import dataclass from dataclasses import field as dataclass_field -from enum import Enum, auto +from enum import Enum from typing import TYPE_CHECKING, Any, Iterator, Type, cast from pypika import Case as PypikaCase @@ -70,12 +70,12 @@ def resolve(self, resolve_context: ResolveContext) -> ResolveResult: class Connector(Enum): - add = auto() - sub = auto() - mul = auto() - div = auto() - pow = auto() - mod = auto() + add = "add" + sub = "sub" + mul = "mul" + div = "truediv" + pow = "pow" + mod = "mod" class CombinedExpression(Expression): @@ -96,7 +96,7 @@ def resolve(self, resolve_context: ResolveContext) -> ResolveResult: ): raise FieldError("Cannot use arithmetic expression between different field type") - operator_func = getattr(operator, self.connector.name) + operator_func = getattr(operator, self.connector.value) return ResolveResult( term=operator_func(left.term, right.term), joins=list(set(left.joins + right.joins)), # dedup joins