From 2d7139363c4bc745e236f864d099d47afe6d9984 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Mon, 20 Mar 2023 13:33:47 +0100 Subject: [PATCH] Fix `SoftDeletableModel.delete()` forwarding positional args to superclass The `soft` argument was made keyword-only, to avoid conflicts with new positional arguments that might be added to Django. It was already conflicting with the `keep_parents` argument. The `using` argument is now passed to the superclass positionally, as otherwise it can overlap with `*args`, resulting in a `TypeError` on calls where `keep_parents` is passed positionally. --- CHANGES.rst | 1 + model_utils/models.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 961d6b3..34cfd37 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -12,6 +12,7 @@ To be released - Make `contribute_to_class()` in `StatusField`, `MonitorField` and `SplitField` forward additional arguments to Django - `SplitField` no longer accepts `no_excerpt_field` as a keyword argument +- Make `soft` argument to `SoftDeletableModel.delete()` keyword-only 4.4.0 (2024-02-10) ------------------ diff --git a/model_utils/models.py b/model_utils/models.py index c816b46..4eb0e63 100644 --- a/model_utils/models.py +++ b/model_utils/models.py @@ -146,7 +146,7 @@ class SoftDeletableModel(models.Model): available_objects = SoftDeletableManager() all_objects = models.Manager() - def delete(self, using=None, soft=True, *args, **kwargs): + def delete(self, using=None, *args, soft=True, **kwargs): """ Soft delete object (set its ``is_removed`` field to True). Actually delete object if setting ``soft`` to False. @@ -155,7 +155,7 @@ class SoftDeletableModel(models.Model): self.is_removed = True self.save(using=using) else: - return super().delete(using=using, *args, **kwargs) + return super().delete(using, *args, **kwargs) class UUIDModel(models.Model):