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

Fix crashing when node attribute is set to None #825

Closed

Conversation

@poxip
Copy link

commented Feb 11, 2017

The compress command was crashing when https://github.com/batiste/django-page-cms was added to project's INSTALLED_APPS. This pull requests provides a simple way to avoid such situations.

/home/michal/dev/ar/demo/lib64/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
  return f(*args, **kwds)

Traceback (most recent call last):
  File "./manage.py", line 8, in <module>
    execute_from_command_line(sys.argv)
  File "/home/michal/dev/ar/demo/lib/python3.4/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/home/michal/dev/ar/demo/lib/python3.4/site-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/michal/dev/ar/demo/lib/python3.4/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/michal/dev/ar/demo/lib/python3.4/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/home/michal/dev/ar/demo/lib/python3.4/site-packages/compressor/management/commands/compress.py", line 291, in handle
    self.compress(sys.stdout, **options)
  File "/home/michal/dev/ar/demo/lib/python3.4/site-packages/compressor/management/commands/compress.py", line 196, in compress
    nodes = list(parser.walk_nodes(template, context=context))
  File "/home/michal/dev/ar/demo/lib/python3.4/site-packages/compressor/offline/django.py", line 148, in walk_nodes
    for node in self.walk_nodes(node, original, context):
  File "/home/michal/dev/ar/demo/lib/python3.4/site-packages/compressor/offline/django.py", line 148, in walk_nodes
    for node in self.walk_nodes(node, original, context):
  File "/home/michal/dev/ar/demo/lib/python3.4/site-packages/compressor/offline/django.py", line 148, in walk_nodes
    for node in self.walk_nodes(node, original, context):
  File "/home/michal/dev/ar/demo/lib/python3.4/site-packages/compressor/offline/django.py", line 143, in walk_nodes
    for node in self.get_nodelist(node, original, context):
  File "/home/michal/dev/ar/demo/lib/python3.4/site-packages/compressor/offline/django.py", line 135, in get_nodelist
    nodelist += getattr(node, attr, [])
TypeError: 'NoneType' object is not iterable```
@karyon karyon referenced this pull request Feb 15, 2017
@karyon

This comment has been minimized.

Copy link
Contributor

commented Feb 15, 2017

Thanks! Seems to be a duplicate of #605, but i like the more explicit solution here better. The thing is, we don't know whether it's a bug in django-compressor or the external libraries... Now that two libraries do this (django-page-cms and sorl-thumbnail), that hints it's django-compressor's problem, but I'm still not sure. I opened batiste/django-page-cms#170, maybe django-page-cms' maintainer can help.

Also, we'd need a test to merge this...

@batiste

This comment has been minimized.

Copy link

commented Mar 9, 2017

Hello.

According to Django https://github.com/django/django/blob/master/django/template/base.py#L894

Any Node instance should have a child_nodelist (at least a class level attribute, this is a bit confusing there)

ForNode and IfNode also have this attribute.

https://github.com/django/django/search?utf8=%E2%9C%93&q=child_nodelists

Anyway what is the error there?

TypeError: 'NoneType' object is not iterable

What is not iterable? is it what self.get_nodelist(node, original, context) return or getattr(node) expect .an iterable? What is the type of the node right there?

@karyon

This comment has been minimized.

Copy link
Contributor

commented Mar 9, 2017

@poxip can you help out?

@batiste

This comment has been minimized.

Copy link

commented Mar 9, 2017

I fixed django-page-cms, here is the simple fix:

batiste/django-page-cms@38853b7

The package 1.9.17 has the fix.

@karyon

This comment has been minimized.

Copy link
Contributor

commented May 10, 2017

okay, i still don't fully understand what's happening, but since @batiste seems to think the bug was inside django-page-cms, i'm going to close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.