serializing foreignkeys assumes value is serializable
|Reported by:||aburgel||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
in django.core.serializers.python, handle_fk_field and handle_m2m_field assume that the foreignkey value requires no conversion, i.e. value_to_string is not called. handle_fk_field sometimes does not even convert the foreignkey value to a string (line 58).
if you're using custom fields whose values are not serializable, then you're given no opportunity for conversion, and in the case of json, if that value isn't a native json type, then you get an exception.
the way to work around this is to write your own serializer or to use natural keys, but given that value_to_string exists, it should be used.
Change History (8)
comment:1 Changed 3 years ago by claudep
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:5 Changed 3 years ago by claudep
- Patch needs improvement set
- Triage Stage changed from Unreviewed to Accepted