cloudinary / pycloudinary

Python package for cloudinary
https://cloudinary.com/documentation/django_integration
Other
254 stars 138 forks source link

AttributeError: 'unicode' object has no attribute 'build_url' #93

Closed dinhn4 closed 7 years ago

dinhn4 commented 7 years ago

I upgraded from version 1.4.0 to 1.7.0. Using Django 1.6.2

I have a field in my models.py icon = CloudinaryField('image', max_length=256, null=True, blank=True)

I used to use it like this to get the image url icon.build_url()

But after upgrade I get this error AttributeError: 'unicode' object has no attribute 'build_url'

Debugged it and discovered that my icon object changes from a CloudinaryResource object with 1.4.0, but now it is treated like a unicode object with 1.7.0.

roeeba commented 7 years ago

Hi @dinhn4, we do not officially support Django 1.6 with our latest SDK, so if you must use Django 1.6, it might be better to use the older SDK version which worked for you. With that said, we might be able to find a workaround for this specific issue. Can you please send us the following information:

  1. The Python version you are using.
  2. Full stack trace of your error.
  3. If possible, the relevant snippet of code that produced the error (so we have some context).

Thanks

dinhn4 commented 7 years ago

Hi @roeeba , Thanks for the response.

  1. Python v2.7.13
  2. ERROR: Processing exception:  (middleware.process_exception)
    ERROR: 'unicode' object has no attribute 'build_url' (middleware.process_exception)
    ERROR: Traceback (most recent call last):
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/core/handlers/base.py", line 114, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/db/transaction.py", line 339, in inner
    return func(*args, **kwargs)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view
    return view_func(request, *args, **kwargs)
    
    File "/vagrant/main/webapp/libs/util/decorators.py", line 92, in inner_decorator
    return function(request, *args, **kwargs)
    
    File "/vagrant/main/webapp/libs/util/decorators.py", line 111, in inner_decorator
    return func(request, *args, **kwargs)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view
    return view_func(request, *args, **kwargs)
    
    File "/vagrant/main/webapp/apps/myaccount/views_myinfo.py", line 963, in video_edit
    context_instance=RequestContext(request))
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/shortcuts/__init__.py", line 29, in render_to_response
    return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/loader.py", line 169, in render_to_string
    return t.render(context_instance)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 140, in render
    return self._render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
    return self.nodelist.render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 854, in render_node
    return node.render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/loader_tags.py", line 123, in render
    return compiled_parent._render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
    return self.nodelist.render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 854, in render_node
    return node.render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/loader_tags.py", line 123, in render
    return compiled_parent._render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
    return self.nodelist.render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 854, in render_node
    return node.render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 854, in render_node
    return node.render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 854, in render_node
    return node.render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/defaulttags.py", line 305, in render
    return nodelist.render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 854, in render_node
    return node.render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/defaulttags.py", line 305, in render
    return nodelist.render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 854, in render_node
    return node.render(context)
    
    File "/srv/python-envs/webapp/lib/python2.7/site-packages/django/template/base.py", line 1125, in render
    return func(*resolved_args, **resolved_kwargs)
    
    File "/vagrant/main/webapp/apps/facility/templatetags/facility_extras.py", line 9, in enterprise_portal_icon
    return icon.build_url()

facility_extras.py

from django import template

register = template.Library()

@register.simple_tag
def enterprise_portal_icon(icon):
    return icon.build_url()

facility_edit.html

{% load facility_extras %}
 src="{%if facility.folder_icon_temp %}{{ facility.folder_icon_temp }}{%else%}{%if community_folder_app.icon %}{% enterprise_portal_icon community_folder_app.icon %}{%else%}{% static 'img/icon_default.png' %}{%endif%}{%endif%}"

community_folder_app is an object with a field icon = CloudinaryField('image', max_length=256, null=True, blank=True)

This is only one example. All other calls to build_url() on a CloudinaryField object breaks for me. Thanks

roeeba commented 7 years ago

Hi @dinhn4, We've investigated your configuration. There are numerous issues when using our latest SDK with Django 1.6.2. We will try to address them in one of our next SDK releases, but we can't currently commit on that since 1.6.2 is old and unsupported by Django since 2015. Right now, if you can't upgrade Django, the best option is to stay with the older SDK version that worked for you.

roeeba commented 7 years ago

Closing this issue due to the time elapsed. Please feel free to either re-open the issue, contact our support at http://support.cloudinary.com or create a new ticket if you have any additional issues/questions.