canonical / canonical/operator
Add support for automatically encoding testing.Relation data to JSON
- Dominant language
- Python
- Stars
- 267
- Forks
- 136
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 28
Description
It's already common practice to have all the field values in relation data be JSON-encoded, and this is the default ops assumes with `Relation.load` and `Relation.save`.
Rather than having a lot of `json.dumps()` in setting up `testing.Relation` objects, and a lot of `json.loads()` in asserts, it would be convenient if there was a way to have this happen transparently.
For example:
```python
data = {'key1': 1, 'key2': 'hello', 'key3': {'subkey': 'foo'}}
rel = testing.Relation(local_app_data=data, json=True)
...
data_out = rel_out.decoded(rel_out.local_app_data) # Or maybe we don't provide decoding only encoding?
```
We'd need to figure out how to handle encoding/decoding fields with values that don't work with a plain json.dumps. Perhaps `encoder=` rather than `json=True`?
Contributor guide
Research direction
Start by reading testing.Relation and the Relation.load and Relation.save behavior described in the issue, focusing on local_app_data and the proposed decoded helper. Clarify whether the API should encode only or also decode, and how values unsupported by plain json.dumps are handled. Done means relation data can be used without repetitive manual JSON conversion and the chosen behavior is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100