to_dict() is used for conversions of OVO objects into
regular dictionaries to be used as plugin return values
to the API layer, etc. It provides the equivalent of
make_<resource>_dict that we use now (without the extension
processing). The values in these dictionaries should be
ready for representation in the API.
The issue was that the OVO to_dict() implementation was
placing complex types right into the dictionary which
would mean that the API would serialize them just by
calling str() on them (as part of json encoding). This
ignored the 'to_primitive' method defined on the OVO
type that defines how a field should be converted.
Therefore, when it came to timestamps to_dict() was
placing native datetime objects into the dictionary
which would convert to microsecond resolution, violating
the expected format of the OVO DateTime type.
This patch fixes the issue by calling 'to_primitive'
on each non-synthetic field in the to_dict() method
to ensure we match the expected format of the type before
we send it out the API.
Reviewed: https:/ /review. openstack. org/365684 /git.openstack. org/cgit/ openstack/ neutron/ commit/ ?id=3756bc51052 6531e3442da6d82 5cc90f44faa355
Committed: https:/
Submitter: Jenkins
Branch: master
commit 3756bc510526531 e3442da6d825cc9 0f44faa355
Author: Kevin Benton <email address hidden>
Date: Mon Sep 5 08:26:01 2016 -0600
Convert OVO fields to primitives for to_dict()
to_dict() is used for conversions of OVO objects into <resource> _dict that we use now (without the extension
regular dictionaries to be used as plugin return values
to the API layer, etc. It provides the equivalent of
make_
processing). The values in these dictionaries should be
ready for representation in the API.
The issue was that the OVO to_dict() implementation was
placing complex types right into the dictionary which
would mean that the API would serialize them just by
calling str() on them (as part of json encoding). This
ignored the 'to_primitive' method defined on the OVO
type that defines how a field should be converted.
Therefore, when it came to timestamps to_dict() was
placing native datetime objects into the dictionary
which would convert to microsecond resolution, violating
the expected format of the OVO DateTime type.
This patch fixes the issue by calling 'to_primitive'
on each non-synthetic field in the to_dict() method
to ensure we match the expected format of the type before
we send it out the API.
Closes-Bug: #1620254 19e1458d4532e2f 70bff0ff9f6
Change-Id: Ic0be54b1d4b231