Repository: matthewwithanm/django-imagekit

Issue #337: source_name_dot_hash could yield `AttributeError` because of unhandled None
Created: 2015-08-05T13:19:54Z
Only noticed this while mocking out branch coverage for a custom namer (which essentially copies most of source_name_dot_hash):
if source_filename becomes None because for whatever reason generator.source does not have a name attribute, then attempting to get the basename will fail because AttributeError: 'NoneType' object has no attribute 'rfind' deep inside os.path.basename()
As an aside, it was a touch difficult to figure out was going on because doing dir(generator) inside a debugging session didn't work, because the builtin dir() is clobbered by the dir = assignment.

Duplicate issue #348: 'NoneType' object has no attribute 'startswith'
Created: 2015-11-12T10:38:41Z
When I try to show a image in template appears these error:
Environment:


Request Method: GET
Request URL: http://local.soofertas.net.br:8000/produto/pm-us72524-curso-de-piano/

Django Version: 1.8.5
Python Version: 3.5.0
Installed Applications:
('django_extensions',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'django.contrib.humanize',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'allauth.socialaccount.providers.facebook',
 'rest_framework',
 'django_filters',
 'bootstrap3',
 'crispy_forms',
 'floppyforms',
 'sendgrid',
 'imagekit',
 'storages',
 'ckeditor',
 'accounts',
 'core',
 'pointlib',
 'cadastro',
 'assinatura',
 'desktop',
 'debug_toolbar')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware')


Traceback:
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/fellipeh/Developer/django/soofertas/core/views.py" in exibe_produto
  140.     return render_to_response('public/show_produto.html', locals(), context_instance=RequestContext(request))
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/shortcuts.py" in render_to_response
  45.             using=using)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/template/loader.py" in render_to_string
  115.                         template_name, context, context_instance, dirs, dictionary)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/template/engine.py" in render_to_string
  221.             return t.render(context_instance)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/template/base.py" in render
  209.                     return self._render(context)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/test/utils.py" in instrumented_test_render
  96.     return self.nodelist.render(context)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/template/base.py" in render_node
  917.         return node.render(context)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  135.         return compiled_parent._render(context)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/test/utils.py" in instrumented_test_render
  96.     return self.nodelist.render(context)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/template/base.py" in render_node
  917.         return node.render(context)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/template/loader_tags.py" in render
  65.                 result = block.nodelist.render(context)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/template/base.py" in render_node
  917.         return node.render(context)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/template/base.py" in render
  957.             output = self.filter_expression.resolve(context)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/template/base.py" in resolve
  647.                 obj = self.var.resolve(context)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/template/base.py" in resolve
  787.             value = self._resolve_lookup(context)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/template/base.py" in _resolve_lookup
  825.                         current = getattr(current, bit)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/imagekit/cachefiles/__init__.py" in url
  84.         return self._storage_attr('url')
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/imagekit/cachefiles/__init__.py" in _storage_attr
  74.             existence_required.send(sender=self, file=self)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/django/dispatch/dispatcher.py" in send
  201.             response = receiver(signal=self, sender=sender, **named)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/imagekit/registry.py" in existence_required_receiver
  53.         self._receive(file, 'on_existence_required')
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/imagekit/registry.py" in _receive
  61.             call_strategy_method(file, callback)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/imagekit/utils.py" in call_strategy_method
  151.         fn(file)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/imagekit/cachefiles/strategies.py" in on_existence_required
  15.         file.generate()
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/imagekit/cachefiles/__init__.py" in generate
  93.             self.cachefile_backend.generate(self, force)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/imagekit/cachefiles/backends.py" in generate
  110.         self.generate_now(file, force=force)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/imagekit/cachefiles/backends.py" in generate_now
  95.         if force or self.get_state(file) not in (CacheFileState.GENERATING, CacheFileState.EXISTS):
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/imagekit/cachefiles/backends.py" in get_state
  69.             exists = self._exists(file)
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/imagekit/cachefiles/backends.py" in _exists
  114.                     or file.storage.exists(file.name))
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/storages/backends/s3boto.py" in exists
  428.         name = self._normalize_name(self._clean_name(name))
File "/Users/fellipeh/.virtualenvs/soofertas/lib/python3.5/site-packages/storages/backends/s3boto.py" in _clean_name
  338.         clean_name = posixpath.normpath(name).replace('\\', '/')
File "/Users/fellipeh/.virtualenvs/soofertas/bin/../lib/python3.5/posixpath.py" in normpath
  332.     initial_slashes = path.startswith(sep)

Exception Type: AttributeError at /produto/pm-us72524-curso-de-piano/
Exception Value: 'NoneType' object has no attribute 'startswith'

The problem is: some images works fine, some not... I try to recreate all cache, but.. same problem...

Closing comment (2016-08-01T23:05:03Z): Also probably related to #337