Skip to content

Fix replaced instance being used when pk-only optimization raises AttributeError #5747

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

Merged

Conversation

ryan-copperleaf
Copy link
Contributor

@ryan-copperleaf ryan-copperleaf commented Jan 15, 2018

Not sure if this is the right place to put the test or where the situation comes up in the real world when not using ORM hacks (like how we found it), but it does test the thing, and the thing is broken in a case that it appears to be intended to handle.

Not sure if this is the right place to put the test or where the situation comes up in the real world when not using ORM hacks (like how we found it), but it *does* test the thing.
@xordoquy
Copy link
Collaborator

Hi,
nice catch and nice work !
I think I would rather catch the ObjectDoesNotExist exception and return an explicit None instead of the fallback on the standard case as it'll do the same thing and possibly perform another DB query.

@ryan-copperleaf
Copy link
Contributor Author

get_attribute is already catching the ObjectDoesNotExist exception, though; the AttributeError comes when a deeper lookup tries to access an attribute on None.

@rpkilby rpkilby self-assigned this Jan 16, 2018
@carltongibson carltongibson added this to the 3.8.3 Release milestone Apr 24, 2018
Copy link
Collaborator

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

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

Hi @ryan-copperleaf. Thank you for this. What a horrible little bug.

@carltongibson carltongibson merged commit a11938c into encode:master Apr 24, 2018
@rpkilby rpkilby modified the milestones: 3.8.3 Release, 3.9 Release Aug 29, 2018
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull request Nov 17, 2020
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.

4 participants