Skip to content

fields.get_attribute: return None for FK lookups - #5727

Closed
blueyed wants to merge 1 commit into
encode:masterfrom
blueyed:get_attribute-return-None
Closed

blueyed wants to merge 1 commit into
encode:masterfrom
blueyed:get_attribute-return-None

Conversation

@blueyed

@blueyed blueyed commented Jan 5, 2018

Copy link
Copy Markdown
Contributor

Ref: #5708 (comment)

TODO:

  • test

@blueyed

blueyed commented Jan 5, 2018

Copy link
Copy Markdown
Contributor Author

"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

rpkilby commented Jan 8, 2018

Copy link
Copy Markdown
Contributor

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

carltongibson commented Mar 16, 2018 •

Copy link
Copy Markdown
Collaborator

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

carltongibson commented Mar 16, 2018 •

Copy link
Copy Markdown
Collaborator

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

Development

Successfully merging this pull request may close these issues.

3 participants