Opened 10 years ago

Closed 10 years ago

#1608 closed defect (worksforme)

When using a non existent field as part of a models representation django throws a TemplateSyntaxError

Reported by: info@… Owned by: adrian
Component: Core (Other) Version: 0.91
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by adrian)

Using this model:

class Product(meta.Model):
    travelCode = meta.CharField('Reiscode', maxlength=7, primary_key=True)

class Unit(meta.Model):
    travelCode = meta.ForeignKey(Product)

    def __repr__(self):
        return "%s %s" % (self.get_travelCode(), self.nonexistentfield)

    class META:
        admin = meta.Admin()

Displaying Unit in the admin interface works for the Unit overview, even though self.nonexistentfield does not exist. When one selects an entry for editting, Django throws the following TemplateSyntaxError:

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/servers/", line 272, in run
    self.result = application(self.environ, self.start_response)

  File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/servers/", line 615, in __call__
    return self.application(environ, start_response)

  File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/handlers/", line 155, in __call__
    response = self.get_response(request.path, request)

  File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/handlers/", line 109, in get_response
    return self.get_technical_error_response(request)

  File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/handlers/", line 139, in get_technical_error_response
    return debug.technical_500_response(request, *sys.exc_info())

  File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/views/", line 126, in technical_500_response
    return HttpResponseServerError(t.render(c), mimetype='text/html')

  File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/template/", line 146, in render
    return self.nodelist.render(context)

  File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/template/", line 707, in render
    bits.append(self.render_node(node, context))

  File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/template/", line 725, in render_node
    result = node.render(context)

  File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/template/", line 112, in render

  File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/template/", line 179, in render
    return self.nodelist_true.render(context)

  File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/template/", line 707, in render
    bits.append(self.render_node(node, context))

  File "/usr/lib/python2.4/site-packages/Django-0.91-py2.4.egg/django/core/template/", line 735, in render_node
    raise wrapped

TemplateSyntaxError: Caught an exception while rendering.

On the front end a similar error is thrown when one tries to use the model object's representation. The error is especially unclear because it refers to a Template error while this essentially is a model error. A model exception stating that the model does not contain such a field would be nicer.

Change History (2)

comment:1 Changed 10 years ago by adrian

  • Description modified (diff)

(Fixed formatting in description)

comment:2 Changed 10 years ago by adrian

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

This appears to be fixed in the magic-removal branch; I can't recreate the problem there. When I put a nonexistent field in a model's __repr__(), the traceback correctly displays the AttributeError.

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