Skip to content

Commit

Permalink
lava_results_app: convert Decimal objects to string storing as YAML
Browse files Browse the repository at this point in the history
Convert Decimal objects to Python strings and then create a regular
YAML ScalarNode to avoid storing Python object types in the results.

Without this patch, YAML text case metadata measurements from the job
results would contain things like this:

    measurement: !!python/object/apply:decimal.Decimal ['15']

which is not standard YAML and can't be imported by non-Python
parsers.  A similar issue can be seen in CSV exports.

With this patch applied, we get this instead:

    measurement: '15.0000000000'

which can be parsed by any standard YAML parser.

Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
  • Loading branch information
gctucker authored and Neil Williams committed Oct 30, 2018
1 parent 26bf0af commit 14b347c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lava_results_app/dbutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
from lava_common.timeout import Timeout


def yaml_decimal_str(dumper, value):
return yaml.ScalarNode(tag=u'tag:yaml.org,2002:str', value=str(value))


yaml.add_representer(decimal.Decimal, yaml_decimal_str)


def _check_for_testset(result_dict, suite):
"""
The presence of the test_set key indicates the start and usage of a TestSet.
Expand Down

0 comments on commit 14b347c

Please sign in to comment.