Skip to content

Fix Trunc functions RecursionError crash on non-MongoDB databases #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2025
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
5 changes: 4 additions & 1 deletion django_mongodb_backend/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ def trunc(self, compiler, connection):
return {"$dateTrunc": lhs_mql}


_trunc_convert_value = TruncBase.convert_value


def trunc_convert_value(self, value, expression, connection):
if connection.vendor == "mongodb":
# A custom TruncBase.convert_value() for MongoDB.
Expand All @@ -224,7 +227,7 @@ def trunc_convert_value(self, value, expression, connection):
# Truncate for Trunc(..., output_field=TimeField)
value = value.time()
return value
return self.convert_value(value, expression, connection)
return _trunc_convert_value(self, value, expression, connection)


def trunc_date(self, compiler, connection):
Expand Down
2 changes: 2 additions & 0 deletions docs/source/releases/5.1.x.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Django MongoDB Backend 5.1.x

- Fixed crash when loading models with a null value for ``ArrayField``\s where
the ``base_field`` uses a database converter.
- Fixed ``RecursionError`` when using ``Trunc`` database functions on non-MongoDB
databases.

5.1.0 beta 3
============
Expand Down
6 changes: 6 additions & 0 deletions docs/source/releases/5.2.x.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ New features
- Added :class:`~.fields.PolymorphicEmbeddedModelField` for storing a model
instance that may be of more than one model class.

Bug fixes
---------

- Fixed ``RecursionError`` when using ``Trunc`` database functions on non-MongoDB
databases.

5.2.0 beta 1
============

Expand Down
Loading