Hello everyone,
I’ve been reviewing the PR for this ticket. This is about how JSONField
is not calling get_prep_value
when adapting the field content in get_db_prep_value
.
I’ve been doing some reading of django/db/models/fields/*.py
and I’ve noticed a few things, that I wanted to discuss with all of you to gain a better understanding of whether any of these items are worth creating tickets for and if they require improvement work to enhance consistency and predictability.
Considering the fact that the base class Field
provides a get_db_prep_value
implementation as follows:
def get_db_prep_value(self, value, connection, prepared=False):
if not prepared:
value = self.get_prep_value(value)
return value
And that:
- There are many
Field
children that overrideget_db_prep_value
, without callingsuper()
, but repeating the same lines explicitly:
def get_db_prep_value(self, value, connection, prepared=False):
if not prepared:
value = self.get_prep_value(value)
# do something else with value...
return modified_value
-
IntegerField
andBinaryField
do callsuper()
inget_db_prep_value
- A small subset of fields would not call
get_prep_value
inget_db_prep_value
at all. These areDurationField
,UUIDField
.
Would it make sense to have those Field
children preparing the value “by hand” calling super()
instead? Shall we also call get_prep_value
(one way or another) in the two fields that do not currently call it? (JSONField
is already being fixed so I’m not counting it here).