Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix serialization error #900

Merged
merged 2 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
# Changelog

### 34.3.1 [#900](https://github.com/openfisca/openfisca-core/pull/900)

#### Bug fix

- Fix serialisation error introduced in [34.2.9](https://github.com/openfisca/openfisca-core/tree/34.2.9) in route `/trace` (Web API)
- This was causing an Internal Server Error
- Notably, `numpy` arrays were not being parsed correctly as not JSON serialisable

### 34.3.0 [#894](https://github.com/openfisca/openfisca-core/pull/894)

_Note: this version has been unpublished due to an issue introduced by 34.2.9 in the Web API. Please use 34.3.1 or a more recent version._

- Update pytest version's upper bound to 6.0.0

### 34.2.9 [#884](https://github.com/openfisca/openfisca-core/pull/884)

_Note: this version has been unpublished due to an issue introduced by 34.2.9 in the Web API. Please use 34.3.1 or a more recent version._

- Refactor simulation tracer implementation
- These changes should be transparent for users
- They should enable more precise performance measures, to come in a later version.
Expand Down
2 changes: 1 addition & 1 deletion openfisca_core/tracers.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _get_flat_trace(self, node: Dict) -> Dict[str, Dict]:
self.key(child) for child in node['children']
],
'parameters': {
self.key(parameter): parameter['value'] for parameter in node['parameters']
self.key(parameter): self.serialize(parameter['value']) for parameter in node['parameters']
},
'value': self.serialize(node['value'])
}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

setup(
name = 'OpenFisca-Core',
version = '34.3.0',
version = '34.3.1',
author = 'OpenFisca Team',
author_email = 'contact@openfisca.org',
classifiers = [
Expand Down
13 changes: 13 additions & 0 deletions tests/core/test_tracers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import json
import numpy as np
from pytest import fixture, mark, raises, approx

Expand Down Expand Up @@ -197,6 +198,18 @@ def test_flat_trace(tracer):
assert trace['b<2019>']['dependencies'] == []


def test_flat_trace_serialize_vectorial_values(tracer):
tracer.enter_calculation('a', 2019)
tracer.record_parameter_access('x.y.z', 2019, np.asarray([100, 200, 300]))
tracer.record_calculation_result(np.asarray([10, 20, 30]))
tracer.exit_calculation()

trace = tracer.get_flat_trace()

assert json.dumps(trace['a<2019>']['value'])
assert json.dumps(trace['a<2019>']['parameters']['x.y.z<2019>'])


def test_flat_trace_with_parameter(tracer):
tracer.enter_calculation('a', 2019)
tracer.record_parameter_access('p', '2019-01-01', 100)
Expand Down