You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently upgraded from Django 1.7 to 1.8 and have run into problems with a subclassed PickledObjectField. The code looks like this:
from picklefield.fields import PickledObjectField as OriginalPickledObjectField
class PickledObjectField(OriginalPickledObjectField):
""" Modified to return an empty `dict` object if empty """
def to_python(self, value):
return super(PickledObjectField, self).to_python(value) or {}
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 used from_db_value. I think the existing from_db_value, which calls to_python, should be fine but the field returns as None instead of an empty dict. I tried overriding the method to call my to_python, but for some reason it doesn't even get called!
I'm totally stumped as to what's going wrong.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: