Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#28040 closed Bug (fixed)

Update SplitArrayWidget to use template-based widget rendering

Reported by: Dariusz Paluch Owned by: nobody
Component: contrib.postgres Version: 1.11
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by dpaluch-rp)

Error: AttributeError: 'SplitArrayWidget' object has no attribute 'template_name'.

Traceback:

Template error:
In template /home/vagrant/apps/pg/python/templates/shared/partials/structure.html, error at line 0
   'SplitArrayWidget' object has no attribute 'template_name'   1 : {% load static_files %}
   2 : {% spaceless %}
   3 : <!DOCTYPE html>
   4 : <html lang="pl" itemscope itemtype="http://schema.org/Organization" {% block html_attrs %}{% endblock html_attrs %} {% block tracking_scripts %}data-pg="google-tag-manager" data-config-google-tag-manager="googleTagManager"{% endblock tracking_scripts %}>
   5 :     <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#">
   6 :         <meta charset="utf-8">
   7 :         <meta http-equiv="X-UA-Compatible" content="IE=edge">
   8 :         {% block head %}
   9 : 
   10 :             {% block meta %}


Traceback:

File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py" in _get_response
  217.                 response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py" in _get_response
  215.                 response = response.render()

File "/usr/local/lib/python3.4/dist-packages/django/template/response.py" in render
  107.             self.content = self.rendered_content

File "/usr/local/lib/python3.4/dist-packages/django/template/response.py" in rendered_content
  84.         content = template.render(context, self._request)

File "/usr/local/lib/python3.4/dist-packages/django/template/backends/django.py" in render
  66.             return self.template.render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in render
  207.                     return self._render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in _render
  199.         return self.nodelist.render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in render
  990.                 bit = node.render_annotated(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in render_annotated
  957.             return self.render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/loader_tags.py" in render
  177.             return compiled_parent._render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in _render
  199.         return self.nodelist.render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in render
  990.                 bit = node.render_annotated(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in render_annotated
  957.             return self.render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/loader_tags.py" in render
  177.             return compiled_parent._render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in _render
  199.         return self.nodelist.render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in render
  990.                 bit = node.render_annotated(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in render_annotated
  957.             return self.render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/loader_tags.py" in render
  177.             return compiled_parent._render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in _render
  199.         return self.nodelist.render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in render
  990.                 bit = node.render_annotated(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in render_annotated
  957.             return self.render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/defaulttags.py" in render
  411.         return strip_spaces_between_tags(self.nodelist.render(context).strip())

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in render
  990.                 bit = node.render_annotated(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in render_annotated
  957.             return self.render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/loader_tags.py" in render
  72.                 result = block.nodelist.render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in render
  990.                 bit = node.render_annotated(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in render_annotated
  957.             return self.render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/loader_tags.py" in render
  72.                 result = block.nodelist.render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in render
  990.                 bit = node.render_annotated(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/base.py" in render_annotated
  957.             return self.render(context)

File "/usr/local/lib/python3.4/dist-packages/django/template/library.py" in render
  225.         _dict = self.func(*resolved_args, **resolved_kwargs)

File "/home/vagrant/apps/pg/python/apps/shared/forms/templatetags/forms.py" in render_field
  85.     if not field:

File "/usr/local/lib/python3.4/dist-packages/django/forms/boundfield.py" in __len__
  64.         return len(self.subwidgets)

File "/usr/local/lib/python3.4/dist-packages/django/utils/functional.py" in __get__
  35.         res = instance.__dict__[self.name] = self.func(instance)

File "/usr/local/lib/python3.4/dist-packages/django/forms/boundfield.py" in subwidgets
  57.             for widget in self.field.widget.subwidgets(self.html_name, self.value(), attrs=attrs)

File "/usr/local/lib/python3.4/dist-packages/django/forms/boundfield.py" in <genexpr>
  56.             BoundWidget(self.field.widget, widget, self.form.renderer)

File "/usr/local/lib/python3.4/dist-packages/django/forms/widgets.py" in subwidgets
  191.         context = self.get_context(name, value, attrs)

File "/usr/local/lib/python3.4/dist-packages/django/forms/widgets.py" in get_context
  212.             'template_name': self.template_name,

Exception Type: AttributeError at /xxxx/
Exception Value: 'SplitArrayWidget' object has no attribute 'template_name'

I'm temporary fix this in my app by subclass django Widget and add template_name property

from django.contrib.postgres import forms as postgres_forms


class SplitArrayWidget(postgres_forms.SplitArrayWidget):
    template_name = ''

Change History (9)

comment:1 by Tim Graham, 8 years ago

Component: Formscontrib.postgres
Description: modified (diff)
Severity: NormalRelease blocker
Summary: AttributeError: 'SplitArrayWidget' object has no attribute 'template_name'SplitArrayWidget isn't updated for template-based widget rendering
Triage Stage: UnreviewedAccepted

comment:2 by Claude Paroz, 8 years ago

Could you provide a more extensive traceback to see where the error occurs?

comment:3 by dpaluch-rp, 8 years ago

Description: modified (diff)

I add traceback to description, and way I fix this

comment:4 by dpaluch-rp, 8 years ago

Description: modified (diff)

comment:5 by Tim Graham, 8 years ago

What does your form look like? I can't reproduce a crash with a straightforward form like:

from django import forms
from django.contrib.postgres.forms import SplitArrayField

class Form(forms.ModelForm):
    tags = SplitArrayField(base_field=forms.CharField(max_length=200), size=3)

comment:6 by Tim Graham, 8 years ago

Has patch: set
Summary: SplitArrayWidget isn't updated for template-based widget renderingUpdate SplitArrayWidget to use template-based widget rendering

comment:7 by Claude Paroz, 8 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by GitHub <noreply@…>, 8 years ago

Resolution: fixed
Status: newclosed

In 1ebd2950:

Fixed #28040 -- Updated SplitArrayWidget to use template-based widget rendering.

Thanks Preston Timmons for review.

comment:9 by Tim Graham <timograham@…>, 8 years ago

In a2975cb0:

[1.11.x] Fixed #28040 -- Updated SplitArrayWidget to use template-based widget rendering.

Thanks Preston Timmons for review.

Backport of 1ebd295082bb0e6b230cf3bc39fd04bee71c2bd7 from master

Note: See TracTickets for help on using tickets.
Back to Top