Attempts to fix update_change_reason for nullable JSONField fields (issue #1181) #1282
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
As reported in issue #1181, the implementation of the utility
update_change_reason()
method does not work for models with a nullable JSONField. This is caused by the slightly more convoluted querying mechanisms that has to be applied for JSONFields, please cf. here: django dev documentationThis attempts to fix this by checking
null
status of the field in question.The strategy assumes that
value
ofNone
is not set at allvalue
ofNone
is actually a "NULL" dictionaryNote: I am aware that this is not the only way to handle this. But it is the convention I am using in my project and this fixed the issue for me. It may be worthwhile to implement a policy switch to decide how to interpret
None
in this specific case.Related Issue
Motivation and Context
I did run into the same issue as the original reporter of the bug report and was stuck. The fix, while admittedly maybe not yet fully universal, depending on the interpretation of a "nullable" JSONField, did solve the issue for me
How Has This Been Tested?
Tested using my local installation. No unit test implemented but this can be done, if required
Types of changes
Checklist:
pre-commit run
command to format and lint.AUTHORS.rst
CHANGES.rst