django-modeltranslation icon indicating copy to clipboard operation
django-modeltranslation copied to clipboard

[Django 6.0] update_fields does not correctly update translation fields when saving model instances

Open ramibch opened this issue 2 months ago • 2 comments

In Django 6.0, the internal QuerySet._update() method received a new argument returning_fields, see definition. django-modeltranslation overrides _update(), but the override does not accept or pass through this new parameter. As a result, when saving a model instance with update_fields, the integration breaks expected behavior.

  File "/home/rami/repos/one/.venv/lib/python3.13/site-packages/django/db/models/base.py", line 1211, in _do_update
    return filtered._update(values, returning_fields)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: MultilingualQuerySet._update() takes 2 positional arguments but 3 were given

Expected: The modeltranslation _update() override should support Django 6.0’s new returning_fields parameter and pass it through to super()._update().

ramibch avatar Dec 07 '25 09:12 ramibch

I have tested my branch locally:

(.venv) one 😎 uv add git+https://github.com/ramibch/django-modeltranslation.git@ticket_802
    Updated https://github.com/ramibch/django-modeltranslation.git (4ef69d3741900b70028ec6259ded3184c500fa26)
Resolved 181 packages in 800ms
      Built django-modeltranslation @ git+https://github.com/ramibch/django-modeltranslation.git@4ef69d3741900b70028e
Prepared 1 package in 535ms
Uninstalled 1 package in 4ms
Installed 1 package in 7ms
 - django-modeltranslation==0.19.17
 + django-modeltranslation==0.1.dev1245+g4ef69d374 (from git+https://github.com/ramibch/django-modeltranslation.git@4ef69d3741900b70028ec6259ded3184c500fa26)
Before the fix: TypeError occured
In [1]: from one.products.tasks import sync_products

In [2]: sync_products()
/home/rami/repos/one/.venv/lib/python3.13/site-packages/botocore/auth.py:422: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
  datetime_now = datetime.datetime.utcnow()
Unhandled exception in task b1b42de5-8546-49c4-adf8-f31739291c1f.
Traceback (most recent call last):
  File "/home/rami/repos/one/.venv/lib/python3.13/site-packages/huey/api.py", line 394, in _execute
    task_value = task.execute()
  File "/home/rami/repos/one/.venv/lib/python3.13/site-packages/huey/api.py", line 834, in execute
    return func(*args, **kwargs)
  File "/home/rami/repos/one/.venv/lib/python3.13/site-packages/huey/contrib/djhuey/__init__.py", line 136, in inner
    return fn(*args, **kwargs)
  File "/home/rami/repos/one/one/products/tasks.py", line 113, in sync_products
    product.save()
    ~~~~~~~~~~~~^^
  File "/home/rami/repos/one/one/db.py", line 118, in save
    super().save(*args, **kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/home/rami/repos/one/.venv/lib/python3.13/site-packages/django/db/models/base.py", line 874, in save
    self.save_base(
    ~~~~~~~~~~~~~~^
        using=using,
        ^^^^^^^^^^^^
    ...<2 lines>...
        update_fields=update_fields,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/rami/repos/one/.venv/lib/python3.13/site-packages/django/db/models/base.py", line 966, in save_base
    updated = self._save_table(
        raw,
    ...<4 lines>...
        update_fields,
    )
  File "/home/rami/repos/one/.venv/lib/python3.13/site-packages/django/db/models/base.py", line 1110, in _save_table
    results = self._do_update(
        base_qs,
    ...<5 lines>...
        returning_fields,
    )
  File "/home/rami/repos/one/.venv/lib/python3.13/site-packages/django/db/models/base.py", line 1211, in _do_update
    return filtered._update(values, returning_fields)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: MultilingualQuerySet._update() takes 2 positional arguments but 3 were given
After the fix: Job completed without errors
n [1]: from one.products.tasks import sync_products

In [2]: sync_products()
/home/rami/repos/one/.venv/lib/python3.13/site-packages/botocore/auth.py:422: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
  datetime_now = datetime.datetime.utcnow()
Out[2]: <Result: task 28ecf1e0-0dc4-47a7-9e2f-def635161ac7>

In [3]:  

ramibch avatar Dec 07 '25 10:12 ramibch

Merged your changes.

I'm not making new release yet. Please test how it works for you with git version. And let's make release a few weeks from now.

last-partizan avatar Dec 08 '25 09:12 last-partizan

I'm also encountering this issue with Django 6.0 and django-modeltranslation 0.19.17.

Environment:

  • Django 6.0
  • Python 3.14
  • django-modeltranslation 0.19.17

Error: TypeError: MultilingualQuerySet._update() takes 2 positional arguments but 3 were given The error occurs when loading fixtures and saving model instances with translated fields.

Thanks for the fix in PR #803 -- seems to be working fine now.

MarcusL11 avatar Dec 11 '25 11:12 MarcusL11

Released new version.

last-partizan avatar Dec 15 '25 10:12 last-partizan