From 33bdcc2d0b6a3cb7654180b53c35c6b11f8694bf Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 17 Jul 2025 09:11:22 -0400 Subject: [PATCH] Fix Trunc functions RecursionError crash on non-MongoDB databases --- django_mongodb_backend/functions.py | 5 ++++- docs/source/releases/5.1.x.rst | 2 ++ docs/source/releases/5.2.x.rst | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/django_mongodb_backend/functions.py b/django_mongodb_backend/functions.py index 492316709..a93a30d3c 100644 --- a/django_mongodb_backend/functions.py +++ b/django_mongodb_backend/functions.py @@ -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. @@ -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): diff --git a/docs/source/releases/5.1.x.rst b/docs/source/releases/5.1.x.rst index 67d988859..8799ceef0 100644 --- a/docs/source/releases/5.1.x.rst +++ b/docs/source/releases/5.1.x.rst @@ -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 ============ diff --git a/docs/source/releases/5.2.x.rst b/docs/source/releases/5.2.x.rst index 54438be83..f0f09ab95 100644 --- a/docs/source/releases/5.2.x.rst +++ b/docs/source/releases/5.2.x.rst @@ -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 ============