Support deferred attributes in JSONField and improve Django compatibility.
Review Request #10469 — Created March 27, 2019 and submitted
JSONField was prone to unwanted queries when working with models
that defferred the JSONField. This wasn't so much a major problem on
Django 1.6, but manifested on newer versions of Django. The core issue
was that, during the model initialization phase,
to load data from the model in order to normalize it, and if the field
was deferred, this act would trigger a query. To fix this, this change
now checks whether the attribute is deferred before performing any
Other changes to the parent
TextFieldin newer versions of Django
broke other aspects of
added, which forced the value to be a string, and in our case this
resulted in some unwanted serialization. We now override this, instead
get_db_prep_value()(which will, in the default implementation,
calls our new method and do the right thing).
On the other end of that process is the
to_python()method, which we
weren't overriding. We now provide this, and have it return a
deserialized representation of the data.
Djblets and Review Board unit tests pass.
Removed an unused import and variable name.
Revision 2 (+182 -24)
Checks run (2 succeeded)