Skip to content

Commit

Permalink
Fix bug combined expression connectors (#1794)
Browse files Browse the repository at this point in the history
* use string for connectors
  • Loading branch information
Abdeldjalil-H authored Dec 1, 2024
1 parent 962de96 commit b382b8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions tortoise/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down

0 comments on commit b382b8c

Please sign in to comment.