Skip to content
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

Fixes issue #175 (possible exception with custom managers hiding som… #176

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JirkaV
Copy link

@JirkaV JirkaV commented Feb 6, 2021

As promised - use Django _default_manager to prevent exceptions when custom manager excludes certain model instances.

@JirkaV JirkaV changed the title Fix for Issue 175 (possible exception with custom managers hiding som… Fix for Issue #175 (possible exception with custom managers hiding som… Feb 6, 2021
@JirkaV JirkaV changed the title Fix for Issue #175 (possible exception with custom managers hiding som… Fixes issue #175 (possible exception with custom managers hiding som… Feb 6, 2021
@@ -68,7 +68,7 @@ def pre_save(sender, instance, raw, using, update_fields, **kwargs):

# created or updated?
if not created:
old_model = sender.objects.get(pk=instance.pk)
old_model = sender._default_manager.get(pk=instance.pk)

Choose a reason for hiding this comment

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

_base_manager i think

Copy link
Collaborator

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

It should be _base_manager which will always return all records, the _default_manager may be filtering out records and can still raise an DoesNotExist exception.

@@ -68,7 +68,7 @@ def pre_save(sender, instance, raw, using, update_fields, **kwargs):

# created or updated?
if not created:
old_model = sender.objects.get(pk=instance.pk)
old_model = sender._default_manager.get(pk=instance.pk)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@sgordon16
Copy link

sgordon16 commented Jul 23, 2024

_base_manager will always return all records, the _default_manager may be filtering out records and can still raise an DoesNotExist exception.
https://docs.djangoproject.com/en/5.0/topics/db/managers/#django.db.models.Model._base_manager

@rgbanasiak
Copy link

Is there a chance that the pull request will be accepted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants