Skip to content

[5.1.x] Backports for 5.1.0b4 release #349

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

Open
wants to merge 5 commits into
base: 5.1.x
Choose a base branch
from
Open
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
13 changes: 1 addition & 12 deletions .github/workflows/zizmor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,5 @@ jobs:
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Get zizmor
run: cargo install zizmor
- name: Run zizmor
run: zizmor --format sarif . > results.sarif
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
category: zizmor
uses: zizmorcore/zizmor-action@1c7106082dbc1753372e3924b7da1b9417011a21
2 changes: 1 addition & 1 deletion django_mongodb_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "5.1.0b4.dev0"
__version__ = "5.1.0b4"

# Check Django compatibility before other imports which may fail if the
# wrong version of Django is installed.
Expand Down
1 change: 0 additions & 1 deletion django_mongodb_backend/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ def execute_sql(
else:
return self._make_result(obj, self.columns)
# result_type is MULTI
cursor.batch_size(chunk_size)
result = self.cursor_iter(cursor, chunk_size, self.columns)
if not chunked_fetch:
# If using non-chunked reads, read data into memory.
Expand Down
5 changes: 4 additions & 1 deletion django_mongodb_backend/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,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 @@ -223,7 +226,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 django_mongodb_backend/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def adapt_timefield_value(self, value):
def _get_arrayfield_converter(self, converter, *args, **kwargs):
# Return a database converter that can be applied to a list of values.
def convert_value(value, expression, connection):
if value is None:
return None
return [converter(x, expression, connection) for x in value]

return convert_value
Expand Down
11 changes: 11 additions & 0 deletions docs/source/releases/5.1.x.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
Django MongoDB Backend 5.1.x
============================

5.1.0 beta 4
============

*July 28, 2025*

- 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.
- Improved ``QuerySet`` performance by removing low limit on server-side chunking.

5.1.0 beta 3
============

Expand Down
7 changes: 6 additions & 1 deletion tests/model_fields_/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ class NestedIntegerArrayModel(models.Model):
class OtherTypesArrayModel(models.Model):
ips = ArrayField(models.GenericIPAddressField(), default=list)
uuids = ArrayField(models.UUIDField(), default=list)
decimals = ArrayField(models.DecimalField(max_digits=5, decimal_places=2), default=list)
decimals = ArrayField(
models.DecimalField(max_digits=5, decimal_places=2),
default=list,
null=True,
blank=True,
)
tags = ArrayField(TagField(), blank=True, null=True)
json = ArrayField(models.JSONField(default=dict), default=list)

Expand Down
3 changes: 2 additions & 1 deletion tests/model_fields_/test_arrayfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ def test_null_from_db_value_handling(self):
instance = OtherTypesArrayModel.objects.create(
ips=["192.168.0.1", "::1"],
uuids=[uuid.uuid4()],
decimals=[decimal.Decimal(1.25), 1.75],
decimals=None,
tags=None,
)
instance.refresh_from_db()
self.assertIsNone(instance.decimals)
self.assertIsNone(instance.tags)
self.assertEqual(instance.json, [])

Expand Down