Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#16565 closed Bug (fixed)

An issue in databrowse's template object_detail.html

Reported by: leopku Owned by: nobody
Component: contrib.databrowse Version: 1.3
Severity: Normal Keywords: databrowse, template
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

1, Steps to reproduce the bug.

i, create a module with a foreignkey and set blank=True and null=True.

ii, create a instance of the module in step 1st, and leave the FK field empty.
iii, install 'databrowse' app and register the model to databrowse.
iv, browse the instance detail info.
An TemplateSyntaxError should be throw out.

2, Issue detail:
TemplateSyntaxError at /databrowse/appname/modelname/objects/objectid/
Caught AttributeError while rendering: 'NoneType' object has no attribute '_get_pk_val'
...
...
...
Template error

In template /opt/Documents/Source/itman/templates/databrowse/object_detail.html, error at line 13
Caught AttributeError while rendering: 'NoneType' object has no attribute '_get_pk_val'

3,How to fix.

Open object_detail.html and go to line 18.
change "{% if field.urls %}" to "{% if field and field.urls %}"

Attachments (1)

django-databrowse-fix-crash-on-null-foreign-keys.patch (651 bytes ) - added by Aymeric Augustin 13 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 by leopku <leo.ss.pku@…>, 13 years ago

  1. Steps to reproduce the bug.
    1. create a module with a foreignkey and set blank=True and null=True.
    2. create a instance of the module in step 1st, and leave the FK field empty.
    3. install 'databrowse' app and register the model to databrowse.
    4. browse the instance detail info. An TemplateSyntaxError? should be throw out.

An TemplateSyntaxError? should be throw out.

  1. Issue detail:

TemplateSyntaxError at /db/services/service/objects/4/

Caught AttributeError while rendering: 'NoneType' object has no attribute '_get_pk_val'

...

...

...

Template error

In template /opt/Documents/Source/itman/templates/databrowse/object_detail.html, error at line 13

Caught AttributeError while rendering: 'NoneType' object has no attribute '_get_pk_val'

...

12 <table class="objectinfo">

13 {% for field in object.fields %}

14

15 <tr class="{% cycle 'odd' 'even' %}">


...

  1. How to fix.

Open object_detail.html and go to line 18.

change "{% if field.urls %}" to "{% if field and field.urls %}"

comment:2 by Aymeric Augustin, 13 years ago

Triage Stage: UnreviewedAccepted

I'm sure I've seen this problem before, but it seems it was never reported in Trac.

I'm attaching the patch I wrote to circumvent this bug on projects where I used databrowse.

comment:3 by anonymous, 13 years ago

aaugustin, thanks a lot for so quick patch.

comment:4 by anonymous, 13 years ago

Has patch: set
Triage Stage: AcceptedReady for checkin

looks good, I need it too so please check in :)

comment:5 by Aymeric Augustin, 13 years ago

My patch doesn't include tests, I'm not sure it can be checked in.

Unfortunately the lack of tests (see #15719) blocks all bugfixes on databrowse.

comment:6 by Jannis Leidel, 13 years ago

Needs tests: set
Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

That said, it still needs tests :)

comment:7 by Preston Holmes, 13 years ago

Triage Stage: AcceptedReady for checkin

I'm wontfixing a bunch of databrowse tickets since it is now deprecated. However since this has a patch, and since databrowse doesn't have tests and is unlikely to get them, I'd propose that some simple fixes like this are allowed in without tests to improve databrowse during its twilight.

comment:8 by Paul McMillan, 13 years ago

Resolution: fixed
Status: newclosed

In [16883]:

Fixed #16565 -- Fixed a databrowse error on null foreign key, even though databrowse is deprecated. Thanks aaugustin for the patch.

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