Do not treat missing non-form data as empty dict - #7199
peterthomassen wants to merge 4 commits into
Conversation
|
@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
c26eb31 to
8b52dc0
Compare
|
@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? |
|
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. |
|
I think this is still current. |
|
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. |
|
I think this is still current. |
|
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. |
|
I think this is still current. |
|
@auvipy Do you think this can be revived? |
|
will come back to this next sun/monday |
|
I'm not convinced that adding new API surface area to REST framework is a net positive. |
|
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. |
There was a problem hiding this comment.
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': {}})
|
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. |
|
@auvipy Any follow-up after the review? Thanks! |
This allows views to distinguish missing payload from empty payload.
Related: #3647, #4566
Description
continuation of #7195