Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 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 aaugustin 3 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 3 years ago by leopku <leo.ss.pku@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  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 Changed 3 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted

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 Changed 3 years ago by anonymous

aaugustin, thanks a lot for so quick patch.

comment:4 Changed 3 years ago by anonymous

  • Has patch set
  • Triage Stage changed from Accepted to Ready for checkin

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

comment:5 Changed 3 years ago by aaugustin

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 Changed 3 years ago by jezdez

  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Ready for checkin to Accepted

That said, it still needs tests :)

comment:7 Changed 3 years ago by ptone

  • Triage Stage changed from Accepted to Ready 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 Changed 3 years ago by PaulM

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

In [16883]:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.