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 Julie Rymer)

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 call get_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 override get_db_prep_value() which is heavier and does not have the same purpose. I think simply replacing connection.ops.adapt_json_value(value, self.encoder) with connection.ops.adapt_json_value(self.get_prep_value(value), self.encoder) in JSONField.get_db_prep_value() would fix this

PS: #34397 seems to be related but in fact is about Django 3.2 so it is not the current issue

Change History (1)

comment:1 by Julie Rymer, 16 months ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top