JSON serialization doesn't always work for YAQL expression results
Bug #1869168 reported by
Renat Akhmerov
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Mistral |
Fix Released
|
Critical
|
Renat Akhmerov |
Bug Description
With disabled YAQL output data conversion, there are cases when we get a result from YAQL and it contains objects of types that are not serializable with the standard json library. For example, FrozenDict (an internal YAQL class), iterators and generators. Those objects may be nested deeply inside the data structure returned by the YAQL engine.
Generally, this issue is not a problem anymore for the internal Mistral code because it was already adjusted to account these types. But whenever we try to serialize this data into a JSON string (e.g. in actions) we'll be getting an issue.
Changed in mistral: | |
assignee: | nobody → Renat Akhmerov (rakhmerov) |
status: | New → Confirmed |
importance: | Undecided → Critical |
milestone: | none → ussuri-3 |
Changed in mistral: | |
status: | Confirmed → In Progress |
To post a comment you must log in.
Reviewed: https:/ /review. opendev. org/714416 /git.openstack. org/cgit/ openstack/ mistral/ commit/ ?id=0dbab33c4c1 aada5bcf96712d3 1ab7fdf3e4d1bb
Committed: https:/
Submitter: Zuul
Branch: master
commit 0dbab33c4c1aada 5bcf96712d31ab7 fdf3e4d1bb
Author: Renat Akhmerov <email address hidden>
Date: Mon Mar 23 17:42:28 2020 +0700
Fix serialization of structures that might contain YAQL types
* When YAQL output data conversion is disabled there's still tion.jsonutils" that is able to_json_ str()" everywhere for JSON tion, including the action "std.http".
an issue caused by presence of not JSON-compatible types within
a YAQL result. The internal Mistral code is already able to deal
with that (due to the previous changes) by checking that and
converting them to what's needed. However, JSON serialization
may still not work if it's done via the standard "json" library.
The library simply doesn't handle those non-standard types and
raises an exception. We have a sanitizing function that all YAQL
results go through, however, it doesn't make sense to do recursive
sanitizing for performance reasons. It does make sense to convert
data as late as possible to avoid redundant data manipulations. So
the sanitizing function handles only the root object in the object
graph. The solution for this problem is to use our own utility
function based on the "oslo_serializa
to deal with at least part of the mentioned types, specifically
FrozenDict and iterators. Generators are still a problem and this
new function takes care of that separately, assuming that any
generator is just a special iterator and hence represents a
collection, i.e. a list in JSON terms. It works for all the cases
we've encountered so far working with YAQL.
* Used the new function "utils.
serializa
* Added necessary unit tests.
Closes-Bug: #1869168 b1dfe68a5bad301 10385130725 c3e1d174b5189be 27c640c4d42
Depends-On: I1081a44a6f305e
Change-Id: I9e73ea7cbba215