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: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Changelog
=========

Unreleased
django-fsm-2 4.1.0 unreleased
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure yet if it will be released as 4.1 or 5.0 (if we manage to include the admin PR)

Suggested change
django-fsm-2 4.1.0 unreleased
django-fsm-2 unreleased

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- Add support for Django 6.0
- Add support for Django 5.2
- Add support for python 3.14
- Add support for python 3.13


Expand Down
31 changes: 22 additions & 9 deletions django_fsm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from functools import partialmethod
from functools import wraps

from django import VERSION as DJANGO_VERSION
from django.apps import apps as django_apps
from django.db import models
from django.db.models import Field
Expand Down Expand Up @@ -479,7 +480,7 @@ def __init__(self, *args, **kwargs):
def state_fields(self):
return filter(lambda field: isinstance(field, FSMFieldMixin), self._meta.fields)

def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_update):
def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_update, returning_fields=None):
# _do_update is called once for each model class in the inheritance hierarchy.
# We can only filter the base_qs on state fields (can be more than one!) present in this particular model.

Expand All @@ -489,14 +490,26 @@ def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_updat
# state filter will be used to narrow down the standard filter checking only PK
state_filter = {field.attname: self.__initial_states[field.attname] for field in filter_on}

updated = super()._do_update(
base_qs=base_qs.filter(**state_filter),
using=using,
pk_val=pk_val,
values=values,
update_fields=update_fields,
forced_update=forced_update,
)
# Django 6.0+ added returning_fields parameter to _do_update
if DJANGO_VERSION >= (6, 0):
updated = super()._do_update(
base_qs=base_qs.filter(**state_filter),
using=using,
pk_val=pk_val,
values=values,
update_fields=update_fields,
forced_update=forced_update,
returning_fields=returning_fields,
)
else:
updated = super()._do_update(
base_qs=base_qs.filter(**state_filter),
using=using,
pk_val=pk_val,
values=values,
update_fields=update_fields,
forced_update=forced_update,
)

# It may happen that nothing was updated in the original _do_update method not because of unmatching state,
# but because of missing PK. This codepath is possible when saving a new model instance with *preset PK*.
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ classifiers = [
"Framework :: Django :: 5.0",
"Framework :: Django :: 5.1",
"Framework :: Django :: 5.2",
"Framework :: Django :: 6.0",
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.8',
Expand All @@ -29,6 +30,7 @@ classifiers = [
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: 3.14',
'Topic :: Software Development :: Libraries :: Python Modules',
]
packages = [{ include = "django_fsm" }]
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ envlist =
py{310,311,312}-dj50
py{310,311,312}-dj51
py{310,311,312,313,314}-dj52
# py{312,313,314}-djmain
py{312,313,314}-dj60
py{312,313,314}-djmain

skipsdist = True

Expand All @@ -14,6 +15,7 @@ deps =
dj50: Django==5.0
dj51: Django==5.1
dj52: Django==5.2
dj60: Django>=6.0a1,<6.1
djmain: https://github.com/django/django/tarball/main

django-guardian
Expand Down