question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'NoneType' object has no attribute 'id'Traceback in django_mark_safe

See original GitHub issue

Describe the bug While running bandit 1.6.2 I get the following output

[tester]	ERROR	Bandit internal error running: django_mark_safe on file ./venv/lib/python3.7/site-packages/django/template/base.py at line 738: 'NoneType' object has no attribute 'id'Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/bandit/core/tester.py", line 64, in run_tests
    result = test(context)
  File "/usr/local/lib/python3.7/site-packages/bandit/plugins/django_xss.py", line 295, in django_mark_safe
    return check_risk(context.node)
  File "/usr/local/lib/python3.7/site-packages/bandit/plugins/django_xss.py", line 243, in check_risk
    secure = evaluate_var(xss_var, parent, node.lineno)
  File "/usr/local/lib/python3.7/site-packages/bandit/plugins/django_xss.py", line 123, in evaluate_var
    to = analyser.is_assigned(node)
  File "/usr/local/lib/python3.7/site-packages/bandit/plugins/django_xss.py", line 89, in is_assigned
    assigned.extend(self.is_assigned_in(node.body))
  File "/usr/local/lib/python3.7/site-packages/bandit/plugins/django_xss.py", line 33, in is_assigned_in
    new_assigned = self.is_assigned(ast_inst)
  File "/usr/local/lib/python3.7/site-packages/bandit/plugins/django_xss.py", line 90, in is_assigned
    assigned.extend(self.is_assigned_in(node.orelse))
  File "/usr/local/lib/python3.7/site-packages/bandit/plugins/django_xss.py", line 33, in is_assigned_in
    new_assigned = self.is_assigned(ast_inst)
  File "/usr/local/lib/python3.7/site-packages/bandit/plugins/django_xss.py", line 89, in is_assigned
    assigned.extend(self.is_assigned_in(node.body))
  File "/usr/local/lib/python3.7/site-packages/bandit/plugins/django_xss.py", line 33, in is_assigned_in
    new_assigned = self.is_assigned(ast_inst)
  File "/usr/local/lib/python3.7/site-packages/bandit/plugins/django_xss.py", line 65, in is_assigned
    if withitem.optional_vars.id == self.var_name.id:
AttributeError: 'NoneType' object has no attribute 'id'

Expected behavior Not seeing a stack trace.

Bandit version

bandit 1.6.2
  python version = 3.7.6 (default, Dec 30 2019, 19:38:26) [Clang 11.0.0 (clang-1100.0.33.16)]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ericwbcommented, Apr 17, 2020

Fixed with #598

1reaction
lukehindscommented, Apr 13, 2020

@ehooo I can see this is your code, do you mind taking a look?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django 'NoneType' object has no attribute 'id' - Stack Overflow
'NoneType' object has no attribute 'id' Traceback: File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response 115.
Read more >
'NoneType' object has no attribute '_inc_path' - Google Groups
Basically I am getting this error. > > AttributeError at /admin/pages/new/wagtail_articles/articleindex/3/ > 'NoneType' object has no attribute '_inc_path ...
Read more >
'NoneType' object has no attribute 'identify'
I'm trying to run this console script, but it gets me wrong: AttributeError: 'NoneType' object has no 'identify' attribute yet it works well...
Read more >
How do I resolve "ERROR Failed to write data to transport with ...
Articles How do I resolve "ERROR Failed to write data to transport with 'NoneType' object has no attribute 'write'" when using the Duo...
Read more >
AttributeError: 'NoneType' object has no attribute 'AsValueString
Trying to create a simple script but getting this error. Don't understand why because i can clearly see the value in it.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found