Skip to content
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

Do not treat missing non-form data as empty dict #7199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

peterthomassen
Copy link
Contributor

This allows views to distinguish missing payload from empty payload.

Related: #3647, #4566

Description

continuation of #7195

@@ -103,6 +103,13 @@ A view inspector class that will be used for schema generation.

Default: `'rest_framework.schemas.openapi.AutoSchema'`

#### DEFAULT_MISSING_DATA
Copy link
Member

Choose a reason for hiding this comment

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

Maybe let's call this something like EMPTY_REQUEST_DATA?

The DEFAULT_XYZ cases make sense because they're things that can be overridden, and are populating the default value. In this case it's not a default case that can be overridden, but rather the base case that it always used if there's an empty request.

Copy link
Member

Choose a reason for hiding this comment

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

Happy to take feedback on alternate naming choices, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I chose "missing" as opposed to "empty" because conventional usage of the word "empty" would suggest that a request body of "", [] or {} is also empty (len(request.data) == 0 after deserialization). I feared that if we call it "EMPTY_DATA", one may think that any "empty-like" payload would be coerced into this value. -- However, I don't feel strongly, as long as the documentation is clear.

Regarding whether it is a default: If by "override", you mean overriding by view attribute or similar, fair enough; one could also argue that the client can override it (by sending data), which would warrant the name DEFAULT_DATA or DEFAULT_REQUEST_DATA.

(Also, it's conceivable that there would a view attribute to override this setting at some point, although right now the request would not have the corresponding context.)

Having said all this, I think my favorite would be DEFAULT_REQUEST_DATA, as I think it is accurate and future-proof. But in the end, I don't have any stakes in the naming, and will be ok with whatever you prefer.

@peterthomassen
Copy link
Contributor Author

@tomchristie Do you need anything else from me to take the next step with this?

This allows views to distinguish missing payload from empty payload.

Related: encode#3647, encode#4566
@peterthomassen
Copy link
Contributor Author

@tomchristie I rebased this PR on top the the current master and resolved conflicts.

Is there anything else I can do to help with this PR?

@stale
Copy link

stale bot commented Apr 25, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 25, 2022
@peterthomassen
Copy link
Contributor Author

I think this is still current.

@stale stale bot removed the stale label Apr 25, 2022
@stale
Copy link

stale bot commented Jul 14, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 14, 2022
@peterthomassen
Copy link
Contributor Author

I think this is still current.

@stale stale bot removed the stale label Jul 14, 2022
@stale
Copy link

stale bot commented Oct 15, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 15, 2022
@peterthomassen
Copy link
Contributor Author

I think this is still current.

@stale stale bot closed this Oct 29, 2022
@peterthomassen
Copy link
Contributor Author

@auvipy Do you think this can be revived?

@auvipy auvipy reopened this Nov 24, 2022
@stale stale bot removed the stale label Nov 24, 2022
@auvipy auvipy self-requested a review November 24, 2022 12:17
@auvipy
Copy link
Member

auvipy commented Nov 24, 2022

will come back to this next sun/monday

@tomchristie
Copy link
Member

I'm not convinced that adding new API surface area to REST framework is a net positive.

@@ -341,7 +341,7 @@ def _parse(self):
if media_type and is_form_media_type(media_type):
empty_data = QueryDict('', encoding=self._request._encoding)
else:
empty_data = {}
empty_data = api_settings.DEFAULT_MISSING_DATA
Copy link
Member

Choose a reason for hiding this comment

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

instead of exposing a new API can we just handle the empty data as None value instead of dict?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was my initial proposal, and I have no objection to doing so. However, please see the discussion in #7195 (comment) (and the context that led up to this post).

Copy link
Member

Choose a reason for hiding this comment

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

what I am suggesting you is based on this comment #7199 (comment) as Tom is reluctant to introduce new API surface to the framework. I saw those discussions as well and do agree with most of them.

Copy link
Contributor Author

@peterthomassen peterthomassen Nov 28, 2022

Choose a reason for hiding this comment

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

Yes, but Tom was even more reluctant to silently change the behavior ("too big of a behavior change" in this earlier comment). He seemed to be more ok with adding the setting, see #7195 (comment).

I have no stakes, and either way is fine for me. It's just think that this question needs clarification between Tom and you, and I can't answer it.

Copy link
Member

Choose a reason for hiding this comment

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

@tomchristie need your input here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants