Skip to content

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

Open
peterthomassen wants to merge 4 commits into
encode:mainfrom
peterthomassen:proper_empty_payload
Open

peterthomassen wants to merge 4 commits into
encode:mainfrom
peterthomassen:proper_empty_payload

Conversation

@peterthomassen

Copy link
Copy Markdown
Collaborator

This allows views to distinguish missing payload from empty payload.

Related: #3647, #4566

Description

continuation of #7195

Comment thread docs/api-guide/settings.md
@peterthomassen

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

stale Bot commented Apr 25, 2022

Copy link
Copy Markdown

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

I think this is still current.

@stale stale Bot removed the stale label Apr 25, 2022
@stale

stale Bot commented Jul 14, 2022

Copy link
Copy Markdown

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

I think this is still current.

@stale stale Bot removed the stale label Jul 14, 2022
@stale

stale Bot commented Oct 15, 2022

Copy link
Copy Markdown

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

I think this is still current.

@stale stale Bot closed this Oct 29, 2022
@peterthomassen

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

auvipy commented Nov 24, 2022

Copy link
Copy Markdown
Collaborator

will come back to this next sun/monday

@lovelydinosaur

Copy link
Copy Markdown
Member

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

Comment thread rest_framework/request.py
@stale

stale Bot commented Apr 27, 2025

Copy link
Copy Markdown

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 27, 2025
@auvipy auvipy removed the stale label Apr 28, 2025
@auvipy
auvipy requested review from a team and Copilot April 28, 2025 02:54

Copilot AI left a comment

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.

Pull Request Overview

This PR updates the handling of missing non-form data so that it is not treated as an empty dict but instead uses a configurable DEFAULT_MISSING_DATA setting. Key changes include:

  • Adding a serializer flag (allow_null) based on query parameters to alter behavior in the view.
  • Updating tests to assert the correct response when no data is provided.
  • Introducing the DEFAULT_MISSING_DATA setting in both the settings and request parsing layers, with corresponding documentation updates.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_testing.py Updates to test cases for missing payload behavior and view configuration.
tests/test_request.py Adjusted expectations for request.data to reflect missing data as None.
rest_framework/settings.py Introduction of DEFAULT_MISSING_DATA with a default value of None.
rest_framework/request.py Use of DEFAULT_MISSING_DATA for non-form missing payloads.
docs/api-guide/settings.md Documentation update for DEFAULT_MISSING_DATA setting.
docs/api-guide/requests.md Updated documentation to explain request.data behavior when no payload is sent.
Comments suppressed due to low confidence (1)

tests/test_testing.py:213

  • Consider adding explicit assertions in the test_missing_post_payload_coerced_dict_uses_default_boolean_value test case to verify that when DEFAULT_MISSING_DATA is overridden to an empty dict, the response data exactly equals {}.
@override_settings(REST_FRAMEWORK={'DEFAULT_MISSING_DATA': {}})

@stale

stale Bot commented Jul 19, 2025

Copy link
Copy Markdown

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 19, 2025
@peterthomassen

Copy link
Copy Markdown
Collaborator Author

@auvipy Any follow-up after the review? Thanks!

@stale stale Bot removed the stale label Jul 19, 2025
Comment thread tests/test_testing.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

5 participants