Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Added
^^^^^
- Add `create()` method to reverse ForeignKey relations, enabling `parent.children.create()` syntax

Fixed
^^^^^
- Fix sqlite decimal filter error with `__gt` (#2020)

0.25
====

Expand Down
4 changes: 4 additions & 0 deletions tests/fields/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ async def test_filter(self):
.first()
)
self.assertEqual(obj, obj0)
objs = await testmodels.DecimalFields.filter(decimal_nodec__gt=2).all()
self.assertIn(obj, objs)
objs = await testmodels.DecimalFields.filter(decimal_nodec__lt=100).all()
self.assertIn(obj, objs)

async def test_f_expression_update(self):
obj0 = await testmodels.DecimalFields.create(decimal=Decimal("1.23456"), decimal_nodec=18.7)
Expand Down
10 changes: 9 additions & 1 deletion tortoise/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ def _process_filter_kwarg(
else:
filter_info = model._meta.get_filter(key)

field_object = None
if "table" in filter_info:
# join the table
join = (
Expand All @@ -405,7 +406,14 @@ def _process_filter_kwarg(
else field_object.to_db_value(value, model)
)
op = filter_info["operator"]
criterion = op(table[filter_info.get("source_field", filter_info["field"])], value)
term: Term = table[filter_info.get("source_field", filter_info["field"])]
if field_object is not None:
func = field_object.get_for_dialect(
model._meta.db.capabilities.dialect, "function_cast"
)
if func is not None:
term = func(field_object, term)
criterion = op(term, value)
return criterion, join

def _resolve_regular_kwarg(
Expand Down