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

CloudinaryField blank=True not working in 1.5.0: object of type 'NoneType' has no len() #81

Closed
michaelgodshall opened this issue Nov 19, 2016 · 2 comments
Assignees
Labels

Comments

@michaelgodshall
Copy link

Today I installed the latest 1.5.0 release in my Django 1.10 project, but CloudinaryField doesn't seem to be working when blank=True:

image = CloudinaryField('image', blank=True)

I'm getting the following error when accessing the object in the admin:

object of type 'NoneType' has no len()

I believe the error is connected to the from_db_value and to_python definitions in cloudinary/models.py. They are checking if value is None, but they should be checking if not value. CloudinaryField is a CharField type and the value of a blank CharField is an empty string, not None.

I am able to fix the error with the above changes, which look like this:

def from_db_value(self, value, expression, connection, context):
    if not value:
        return value
    return self.parse_cloudinary_resource(value)

def to_python(self, value):
    if isinstance(value, CloudinaryResource):
        return value
    elif isinstance(value, UploadedFile):
        return value
    elif not value:
        return value
    else:
        return self.parse_cloudinary_resource(value)

The previous version of cloudinary implemented this correctly, so I'm not sure why this was changed in 1.5.0.

@roeeba
Copy link
Collaborator

roeeba commented Nov 20, 2016

Hi @godshall , Can you please share with us the following details?

  1. Full error message and stacktrace.
  2. Which python version are you using?

Thanks

@michaelgodshall
Copy link
Author

Environment:

Request Method: GET
Request URL: //localhost:3000/admin/actions/action/3/change/

Django Version: 1.10.2
Python Version: 3.5.0

Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'rest_framework',
'my_site',
'actions']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.gzip.GZipMiddleware',
'debreach.middleware.RandomCommentMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']

Template error:
In template /Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/contrib/admin/templates/admin/change_form.html, error at line 33
object of type 'NoneType' has no len() 23 : {% endblock %}
24 : {% endif %}
25 :
26 : {% block content %}


27 : {% block object-tools %}
28 : {% if change %}{% if not is_popup %}
29 :

    30 : {% block object-tools-items %}
    31 :

  • 32 : {% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
    33 : {% trans "History" %}
    34 :

  • 35 : {% if has_absolute_url %}
  • {% trans "View on site" %}
  • {% endif %}
    36 : {% endblock %}
    37 :

38 : {% endif %}{% endif %}
39 : {% endblock %}
40 : <form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form" novalidate>{% csrf_token %}{% block form_top %}{% endblock %}
41 :

42 : {% if is_popup %}{% endif %}
43 : {% if to_field %}{% endif %}

Traceback:

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
39. response = get_response(request)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
217. response = self.process_exception_by_middleware(e, request)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
215. response = response.render()

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/response.py" in render
109. self.content = self.rendered_content

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/response.py" in rendered_content
86. content = template.render(context, self._request)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/backends/django.py" in render
66. return self.template.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render
208. return self._render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/test/utils.py" in instrumented_test_render
94. return self.nodelist.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render
994. bit = node.render_annotated(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render_annotated
961. return self.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/loader_tags.py" in render
174. return compiled_parent._render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/test/utils.py" in instrumented_test_render
94. return self.nodelist.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render
994. bit = node.render_annotated(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render_annotated
961. return self.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/loader_tags.py" in render
174. return compiled_parent._render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/test/utils.py" in instrumented_test_render
94. return self.nodelist.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render
994. bit = node.render_annotated(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render_annotated
961. return self.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/loader_tags.py" in render
70. result = block.nodelist.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render
994. bit = node.render_annotated(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render_annotated
961. return self.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/loader_tags.py" in render
70. result = block.nodelist.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render
994. bit = node.render_annotated(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render_annotated
961. return self.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/defaulttags.py" in render
209. nodelist.append(node.render_annotated(context))

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render_annotated
961. return self.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/loader_tags.py" in render
210. return template.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render
210. return self._render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/test/utils.py" in instrumented_test_render
94. return self.nodelist.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render
994. bit = node.render_annotated(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render_annotated
961. return self.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/defaulttags.py" in render
209. nodelist.append(node.render_annotated(context))

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render_annotated
961. return self.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/defaulttags.py" in render
209. nodelist.append(node.render_annotated(context))

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render_annotated
961. return self.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/defaulttags.py" in render
315. return nodelist.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render
994. bit = node.render_annotated(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render_annotated
961. return self.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/defaulttags.py" in render
315. return nodelist.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render
994. bit = node.render_annotated(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render_annotated
961. return self.render(context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render
1050. return render_value_in_context(output, context)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/template/base.py" in render_value_in_context
1028. value = force_text(value)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/utils/encoding.py" in force_text
76. s = six.text_type(s)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/utils/html.py" in
391. klass.str = lambda self: mark_safe(klass_str(self))

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/forms/boundfield.py" in str
43. return self.as_widget()

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/forms/boundfield.py" in as_widget
89. attrs = self.build_widget_attrs(attrs, widget)

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/forms/boundfield.py" in build_widget_attrs
238. if widget.use_required_attribute(self.initial) and self.field.required and self.form.use_required_attribute:

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/django/forms/widgets.py" in use_required_attribute
441. return super(ClearableFileInput, self).use_required_attribute(initial) and not initial

File "/Users/me/.virtualenvs/my-site/lib/python3.5/site-packages/cloudinary/init.py" in len
129. return len(self.public_id)

Exception Type: TypeError at /admin/actions/action/3/change/
Exception Value: object of type 'NoneType' has no len()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants