pytm icon indicating copy to clipboard operation
pytm copied to clipboard

Error with data field in input JSON

Open jmrenshaw opened this issue 3 years ago • 6 comments

When using the JSON model format as input to create a report I am getting an error "expecting a list of pytm.Data, item number 0 is a <class 'str'>" (line 213 in the code snippet). https://github.com/izar/pytm/blob/679ea0df19b7b92e7d8359891d53f7ed794d54a3/pytm/pytm.py#L194-L218 My input JSON for data and flows looks like this: "flows": [ { "name": "Actor 1 to Actor 2", "source": "Actor 1", "sink": "Actor 2", "order": 1, "data": [ "Data" ] },{ "name": "Actor 2 to Actor 3", "source": "Actor 2", "sink": "Actor 3", "description": "Another data flow", "data": [ ] } ], "data": [ { "name": "Data", "format": "Text", "isPII": true } ]

Which I believe matches the JSON format when using the JSON output of the CLI tool. Below is the function which leads to calling varData when it creates the Dataflow object. It seems like the varData function doesn't deal with a list of data name strings. input.json in the tests folder doesn't have a data field in it. Since data objects are not in either the boundaries, elements or flows section of the JSON should they be dealt with using their own function e.g. decode_data? https://github.com/izar/pytm/blob/679ea0df19b7b92e7d8359891d53f7ed794d54a3/pytm/json.py#L92-L107

jmrenshaw avatar Aug 24 '22 10:08 jmrenshaw

What does your command line look like?

izar avatar Aug 24 '22 14:08 izar

Hi, I am not using the command line, I am using the load function imported to a python file to create a model object.

jmrenshaw avatar Aug 24 '22 14:08 jmrenshaw

I'll have to go back to that part of the code. Did you try to save a model as JSON and then load it back again?

izar avatar Aug 24 '22 15:08 izar

Hi @izar , apologies for such a belated response on this! One thing I have tried is running your unit tests but renaming output.json to input.json as this is a much more complete model in terms of different functions. The test now fails with the following:

====================================================================== ERROR: test_json_loads (tests.test_pytmfunc.TestTM)

Traceback (most recent call last): File "/home/jon/pytm_clone/tests/test_pytmfunc.py", line 343, in test_json_loads tm = loads(contents) File "/home/jon/pytm_clone/pytm/json.py", line 23, in loads result = json.loads(s, object_hook=decode) File "/usr/lib/python3.10/json/init.py", line 359, in loads return cls(**kw).decode(s) File "/usr/lib/python3.10/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.10/json/decoder.py", line 353, in raw_decode obj, end = self.scan_once(s, idx) File "/home/jon/pytm_clone/pytm/json.py", line 41, in decode boundaries = decode_boundaries(data.pop("boundaries", [])) File "/home/jon/pytm_clone/pytm/json.py", line 61, in decode_boundaries e = Boundary(name, **e) File "/home/jon/pytm_clone/pytm/pytm.py", line 1769, in init super().init(name, **kwargs) File "/home/jon/pytm_clone/pytm/pytm.py", line 1301, in init setattr(self, key, value) File "/home/jon/pytm_clone/pytm/pytm.py", line 248, in set raise ValueError( ValueError: expecting an Controls value, got a <class 'dict'>


jmrenshaw avatar May 05 '23 14:05 jmrenshaw

thanks for the report! I'll take a look at it as soon as time permits.

izar avatar May 05 '23 14:05 izar