Closed tisdall closed 5 years ago
I think the issue is from_db_value
isn't called on assignment where the old system with the metaclass caused the to_python
to be called.
Are there any suggestions on how to modify my subclass such that NULL values can be treated like an empty dict?
Sorry for the delay on the reply here. It looks like Django's from_db_value
introduction includes guidelines on how such a behavior can be restored.
The new approach doesn’t call the to_python() method on assignment as was the case with SubfieldBase. If you need that behavior, reimplement the Creator class from Django’s source code in your project.
I'll close this for now as this has become the de-facto behavior of model fields at this point.
I recently upgraded from Django 1.7 to 1.8 and have run into problems with a subclassed
PickledObjectField
. The code looks like this:I had some spots where the field was sometimes
None
/NULL but wanted to treat those as equivalent to an empty dictionary. It worked fine until I upgraded to Django 1.8 .I saw that in 1.8 it stops using the
models.SubfieldBase
metaclass and instead usedfrom_db_value
. I think the existingfrom_db_value
, which callsto_python
, should be fine but the field returns asNone
instead of an empty dict. I tried overriding the method to call myto_python
, but for some reason it doesn't even get called!I'm totally stumped as to what's going wrong.