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

Error with data field in input JSON #204

Open
jmrenshaw opened this issue Aug 24, 2022 · 6 comments
Open

Error with data field in input JSON #204

jmrenshaw opened this issue Aug 24, 2022 · 6 comments

Comments

@jmrenshaw
Copy link

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

@izar
Copy link
Collaborator

izar commented Aug 24, 2022

What does your command line look like?

@jmrenshaw
Copy link
Author

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

@izar
Copy link
Collaborator

izar commented Aug 24, 2022

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?

@jmrenshaw
Copy link
Author

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'>


@izar
Copy link
Collaborator

izar commented May 5, 2023

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

@clemebip
Copy link

any news about this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants