Skip to content

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
# 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.

Copy link
Contributor

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.

# 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
Contributor

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?

@adam-hrb
Copy link

Hi I also encountered this - could that be fixed?

@tarasinf
Copy link

Any progress with this?

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.

7 participants