jsonutils.to_primitive does not follow the protocol required by json.dump

Bug #1864678 reported by Balazs Gibizer
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo.serialization
Medium
Unassigned

Bug Description

"If specified, default should be a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError. If not specified, TypeError is raised." [1]

So jsonutils.to_primitive[2], that is used as default in jsonutils.dumps, is broken as
i) it returns the same object if the object is not serializable instead of raising TypeError
ii) it warns the user of the lib that ValueError will be raised from 3.0 instead of TypeError
iii) oslo.serialization 3.0 is released without changing that warning to a real exception raise

[1] https://docs.python.org/3.6/library/json.html#json.dump
[2] https://github.com/openstack/oslo.serialization/blob/301b0cb54c82a837913dc9d71e792eb4df9b7273/oslo_serialization/jsonutils.py#L191

Revision history for this message
Ben Nemec (bnemec) wrote :

It looks like we need to address Glance before we remove this. I see the warning occurring in their logs on a regular basis: http://logstash.openstack.org/#dashboard/file/logstash.json?query=message%3A%5C%22will%20raise%20ValueError%5C%22

Changed in oslo.serialization:
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Ben Nemec (bnemec) wrote :

I also see some log entries from an ironic py38 job and a nova lower-constraints job.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers