Skip to content

Remove deprecated model manager. #480

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGES
=======

Unreleased
----------

- SoftDeletableModel no longer uses SoftDeletableManager as its default manager (GH-364)

4.1.1 (2020-12-01)
------------------
- Applied `isort` to codebase (Refs GH-#402)
Expand Down
4 changes: 1 addition & 3 deletions docs/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ This abstract base class just provides a field ``is_removed`` which is
set to True instead of removing the instance. Entities returned in
manager ``available_objects`` are limited to not-deleted instances.

Note that relying on the default ``objects`` manager to filter out not-deleted
instances is deprecated. ``objects`` will include deleted objects in a future
release.
Note that the default manager includes soft-deleted instances.


UUIDModel
Expand Down
14 changes: 0 additions & 14 deletions model_utils/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,25 +274,11 @@ class SoftDeletableManagerMixin:
"""
_queryset_class = SoftDeletableQuerySet

def __init__(self, *args, _emit_deprecation_warnings=False, **kwargs):
self.emit_deprecation_warnings = _emit_deprecation_warnings
super().__init__(*args, **kwargs)

def get_queryset(self):
"""
Return queryset limited to not removed entries.
"""

if self.emit_deprecation_warnings:
warning_message = (
"{0}.objects model manager will include soft-deleted objects in an "
"upcoming release; please use {0}.available_objects to continue "
"excluding soft-deleted objects. See "
"https://django-model-utils.readthedocs.io/en/stable/models.html"
"#softdeletablemodel for more information."
).format(self.model.__class__.__name__)
warnings.warn(warning_message, DeprecationWarning)

kwargs = {'model': self.model, 'using': self._db}
if hasattr(self, '_hints'):
kwargs['hints'] = self._hints
Expand Down
3 changes: 1 addition & 2 deletions model_utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@ class SoftDeletableModel(models.Model):
class Meta:
abstract = True

objects = SoftDeletableManager(_emit_deprecation_warnings=True)
available_objects = SoftDeletableManager()
all_objects = models.Manager()
available_objects = SoftDeletableManager()

def delete(self, using=None, soft=True, *args, **kwargs):
"""
Expand Down
6 changes: 0 additions & 6 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,8 @@ class StatusFieldChoicesName(models.Model):


class SoftDeletable(SoftDeletableModel):
"""
Test model with additional manager for full access to model
instances.
"""
name = models.CharField(max_length=20)

all_objects = models.Manager()


class CustomSoftDelete(SoftDeletableModel):
is_read = models.BooleanField(default=False)
Expand Down
11 changes: 7 additions & 4 deletions tests/test_models/test_softdeletable_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ def test_instance_purge(self):
def test_instance_purge_no_connection(self):
instance = SoftDeletable.available_objects.create(name='a')

self.assertRaises(ConnectionDoesNotExist, instance.delete,
using='other', soft=False)
self.assertRaises(
ConnectionDoesNotExist, instance.delete, using='other', soft=False
)

def test_deprecation_warning(self):
self.assertWarns(DeprecationWarning, SoftDeletable.objects.all)
def test_default_manager_includes_removed(self):
SoftDeletable.available_objects.create(name='a', is_removed=True)
self.assertEqual(SoftDeletable.available_objects.count(), 0)
self.assertEqual(SoftDeletable._default_manager.count(), 1)