Skip to content

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

Open
JirkaV wants to merge 2 commits intosoynatan:masterfrom
JirkaV:Issue_175
Open

Fixes issue #175 (possible exception with custom managers hiding som…#176
JirkaV wants to merge 2 commits intosoynatan:masterfrom
JirkaV:Issue_175

Conversation

@JirkaV
Copy link
Copy Markdown

@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)
Copy link
Copy Markdown

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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@sgordon16
Copy link
Copy Markdown
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
Copy Markdown

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

@adam-hrb
Copy link
Copy Markdown

Hi I also encountered this - could that be fixed?

@tarasinf
Copy link
Copy Markdown

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