You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, came across a potential bug that when writing to nested structures it only works when the nested structures is an array of structures. I modified the test_bytes_from_dict test to give an example. The test fails due to KeyError:
tests/test_ads.py", line 848, in test_bytes_from_dict
self.assertEqual(bytes_list, pyads.bytes_from_dict(values, structure_def))
pyads/pyads/ads.py", line 441, in bytes_from_dict
values=var[i], structure_def=plc_datatype
~~~^^^
KeyError: 0
Error comes from the fact that var can be of type OrderedDict and not of type list as is expected:
I would think this is not expected behavior as this forces the user to wrap the nested structures inside list comprehension if they are not array types. My own use case was to be able to do a read_structure_by_name (this contains nested structures) -> modify a value from this structure -> Write the modified structure back into the PLC using write_structure_by_name. Due to this error I am unable to do it without modifying the type of the nested structure to be a list. Maybe it would be good to check in bytes_from_dict that the var is actually a list?
The text was updated successfully, but these errors were encountered:
msfur
added a commit
to msfur/pyads
that referenced
this issue
Jan 13, 2025
Hi, came across a potential bug that when writing to nested structures it only works when the nested structures is an array of structures. I modified the test_bytes_from_dict test to give an example. The test fails due to
KeyError
:This throws an error:
Error comes from the fact that var can be of type OrderedDict and not of type list as is expected:
I would think this is not expected behavior as this forces the user to wrap the nested structures inside list comprehension if they are not array types. My own use case was to be able to do a
read_structure_by_name
(this contains nested structures) -> modify a value from this structure -> Write the modified structure back into the PLC usingwrite_structure_by_name
. Due to this error I am unable to do it without modifying the type of the nested structure to be a list. Maybe it would be good to check in bytes_from_dict that the var is actually a list?The text was updated successfully, but these errors were encountered: