Skip to content

fields.get_attribute: return None for FK lookups #5727

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

Closed
wants to merge 1 commit into from

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Jan 5, 2018

Ref: #5708 (comment)

TODO:

  • test

@blueyed
Copy link
Contributor Author

blueyed commented Jan 5, 2018

"lint" CI failure is unrelated.

Some advice for where to put a test would be nice, if this change makes sense in general.
(no current tests are failing)

@carltongibson carltongibson requested a review from rpkilby January 8, 2018 09:55
@rpkilby rpkilby self-assigned this Jan 8, 2018
@rpkilby
Copy link
Member

rpkilby commented Jan 8, 2018

Adding this to my todo list. In general, I need to go back and check the behavior around missing FK's, similar to the changes made in #5375.

@carltongibson
Copy link
Collaborator

carltongibson commented Mar 16, 2018

Hey @blueyed. Sorry for the slow follow-up here.

Some advice for where to put a test would be nice...

I don't mind where so much to begin — perhaps just drop something into test fields — but a reproduce in a test case in this PR would be great. Any chance you can whip one up?

Thanks!

carltongibson added a commit to carltongibson/django-rest-framework that referenced this pull request Mar 16, 2018
carltongibson added a commit to carltongibson/django-rest-framework that referenced this pull request Mar 16, 2018
carltongibson added a commit that referenced this pull request Mar 16, 2018
… when path components may be null.

Ref #5375, #5727
@carltongibson carltongibson force-pushed the get_attribute-return-None branch from b976867 to 0a77ff6 Compare March 16, 2018 13:56
@carltongibson
Copy link
Collaborator

carltongibson commented Mar 16, 2018

OK… I added a test covering the problem use-case from #5375 (in #5880). I've rebased this on that.
It'll now fail.

From #5375 (comment)

Without the guard, a subsequent attr would cause an AttributeError to be raised instead, allowing the default to be used.

In order to support correct default behaviour with dotted sources where any path element may be None we must raise the AttributeError in rest_framework.fields.get_attribute.

Once the build completes, I will close this one as-is. It looks like a non-starter. (Happy to reopen, or do it on a new PR, if we can make progress.)

I'm still looking at the underlying issue.

@blueyed blueyed deleted the get_attribute-return-None branch April 27, 2018 17:59
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.

3 participants