Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#2566 closed defect (fixed)

Setting TEMPLATE_STRING_IF_INVALID = 'notempty' breaks admin user creation

Reported by: django@… Owned by: adrian
Component: contrib.admin Version: master
Severity: normal Keywords: admin user add
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If you set TEMPLATE_STRING_IF_INVALID to a non empty string for debugging purposes, then the admin user add will be broken.

AttributeError at /apps/admin/auth/user/add/
'str' object has no attribute 'field'
Request Method: 	GET
Request URL: 	http://localhost:8000/apps/admin/auth/user/add/
Exception Type: 	AttributeError
Exception Value: 	'str' object has no attribute 'field'
Exception Location: 	C:\pycon-tech\django\contrib\admin\templatetags\admin_modify.py in render, line 161
Template error

In template C:\pycon-tech\django\contrib\admin\templates\admin/change_form.html, error at line 55
Caught an exception while rendering: 'str' object has no attribute 'field'
45 	{% block after_field_sets %}{% endblock %}
46 	{% if change %}
47 	{% if ordered_objects %}
48 	<fieldset class="module"><h2>{% trans "Ordering" %}</h2>
49 	<div class="form-row{% if form.order_.errors %} error{% endif %} ">
50 	{% if form.order_.errors %}{{ form.order_.html_error_list }}{% endif %}
51 	<p><label for="id_order_">{% trans "Order:" %}</label> {{ form.order_ }}</p>
52 	</div></fieldset>
53 	{% endif %}
54 	{% endif %}
55 	{% for related_object in inline_related_objects %}{% edit_inline related_object %}{% endfor %}
56 	{% block after_related_objects %}{% endblock %}
57 	{% submit_row %}
58 	{% if add %}
59 	<script type="text/javascript">document.getElementById("{{ first_form_field_id }}").focus();</script>
60 	{% endif %}
61 	{% if auto_populated_fields %}
62 	<script type="text/javascript">
63 	{% auto_populated_field_script auto_populated_fields change %}
64 	</script>
65 	{% endif %}
Traceback (most recent call last):
File "C:\pycon-tech\django\template\__init__.py" in render_node
  706. result = node.render(context)
File "C:\pycon-tech\django\template\defaulttags.py" in render
  118. nodelist.append(node.render(context))
File "C:\pycon-tech\django\contrib\admin\templatetags\admin_modify.py" in render
  161. if relation.field.rel.edit_inline == models.TABULAR:

  AttributeError at /apps/admin/auth/user/add/
  'str' object has no attribute 'field'
 154. class EditInlineNode(template.Node):
 155. def __init__(self, rel_var):
 156.     self.rel_var = rel_var
 157.
 158. def render(self, context):
 159.     relation = template.resolve_variable(self.rel_var, context)
 160.     context.push()

*161.     if relation.field.rel.edit_inline == models.TABULAR: ...

 162.         bound_related_object_class = TabularBoundRelatedObject
 163.     else:
 164.         bound_related_object_class = StackedBoundRelatedObject

relation = '[' and
related_object = '[' in the context.
obviously ths is teh first character of my TEMPLATE_STRING_IF_INVALID. How it got there, I don't know yet.

context  	
[{}, {'forloop': {'parentloop': {}, 'last': False, 'counter': 1, 'revcounter0': 15, 'revcounter': 16, 'counter0': 0, 'first': True}, 'related_object': '['}, ...

Change History (2)

comment:1 Changed 9 years ago by filipwasilewski@…

I haven't noticed such problem, but instead of that I have observed a different one while setting TEMPLATE_STRING_IF_INVALID to nonempty.
The action {{ form_url }} param in the user add form (which extends change_form.html) is uninitialized, which in turn results in an invalid action url.

-> 127.0.0.1:8000/admin/auth/user/add/{{TEMPLATE_STRING_IF_INVALID}}

comment:2 Changed 9 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [3901]) Fixes #2384,#2566 -- Clarify the role that TEMPLATE_STRING_IF_INVALID plays in the template system, and the problems that can occur if it is used on a production site.

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