Opened 16 months ago
Last modified 15 months ago
#34539 closed Bug
`get_prep_value` no longer called for JSONField — at Version 1
Reported by: | Julie Rymer | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 4.2 |
Severity: | Release blocker | Keywords: | |
Cc: | Simon Charette, Florian Apolloner, Tim Graham | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Hello, I just upgraded from django 4.1 to 4.2 and I have a custom JSONField
with a get_prep_value()
override that stopped working. After searching a bit, I saw that was because JSONField.get_prep_value()
is no longer called in 4.2 (5c23d9f0c32f166c81ecb6f3f01d5077a6084318).
I think this issue need a resolution either:
JSONField
should callget_prep_value()
like all other fields type, because this is the method that the documentation tell us to override in custom fields. Otherwise we need to overrideget_db_prep_value()
which is heavier and does not have the same purpose. I think simply replacingconnection.ops.adapt_json_value(value, self.encoder)
withconnection.ops.adapt_json_value(self.get_prep_value(value), self.encoder)
inJSONField.get_db_prep_value()
would fix this
- If there is a good reason to no longer call
get_prep_value()
, this exception forJSONField
should be clearly documented in custom get_prep_value() doc. It should also be added to Backwards incompatible changes in 4.2 release note because I got stuck with this issue with no warning when migrating.
PS: #34397 seems to be related but in fact is about Django 3.2 so it is not the current issue
Note:
See TracTickets
for help on using tickets.