#34539: `get_prep_value` no longer called for JSONField
-------------------------------------+-------------------------------------
               Reporter:  Julie      |          Owner:  nobody
  Rymer                              |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  4.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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.

 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
 
[https://docs.djangoproject.com/en/4.2/ref/models/fields/#django.db.models.Field
 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

 - If there is a good reason to no longer call `get_prep_value()`, this
 exception for `JSONField` should be clearly documented in
 
[https://docs.djangoproject.com/en/4.2/ref/models/fields/#django.db.models.Field.get_prep_value
 custom get_prep_value() doc]. It should also be added to
 [https://docs.djangoproject.com/en/4.2/releases/4.2/#backwards-
 incompatible-changes-in-4-2 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

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34539>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070187e62255f2-a9c0c5b7-473c-4043-afb5-3bd63ebb2cfb-000000%40eu-central-1.amazonses.com.

Reply via email to