izar / pytm

A Pythonic framework for threat modeling
Other
861 stars 161 forks source link

Got an error "AttributeError: 'str' object has no attribute 'name'" when using the "--sqldump SQLDUMP". #221

Closed darwin-xu closed 2 months ago

darwin-xu commented 9 months ago

I encountered the error:

dxu@remotedev-dxu-sea:~/open-source/pytm> ./tm.py --sqldump SQLDUMP
Traceback (most recent call last):
  File "./tm.py", line 127, in <module>
    tm.process()
  File "/ifs/home/dxu/open-source/pytm/pytm/pytm.py", line 1055, in process
    self.sqlDump(result.sqldump)
  File "/ifs/home/dxu/open-source/pytm/pytm/pytm.py", line 1149, in sqlDump
    for k, v in serialize(e).items():
  File "/ifs/home/dxu/open-source/pytm/pytm/pytm.py", line 1873, in serialize
    value = [v.id if isinstance(v, Finding) else v.name for v in value]
  File "/ifs/home/dxu/open-source/pytm/pytm/pytm.py", line 1873, in <listcomp>
    value = [v.id if isinstance(v, Finding) else v.name for v in value]
AttributeError: 'str' object has no attribute 'name'

Is it a mistake on my end, or could it be a bug?

raphaelahrens commented 9 months ago

Hi,

it looks like you have an Iterable which holds a string as a value. Without the tm.py it is difficult to see the exact problem, but the line which fails is taking a list, tuple or iterator and the values in the iterable need to be Findinds or have a name attribute.

Without an example it is difficult to see if this is a usability issue or not.

sergebelokamen commented 2 months ago

I am having the same issue. The issue can be replicated with the 'tm.py' file that comes with default installation.

The issue appears to be triggered by 'assumptions' (tm.assumptions = ["No assumptions."]). Removing or commenting the line out generates SQLite DB...