Code

Opened 9 years ago

Closed 7 years ago

#189 closed defect (fixed)

Inline editing of foreign keys doesn't do pretty error handling.

Reported by: Nick Stenning Owned by: adrian
Component: contrib.admin Version:
Severity: normal Keywords: admin interface error handling schema null fields
Cc: Triage Stage: Ready for checkin
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When adding/editing foreign keys in the admin interface, any violation of NOT NULL or other schema specifications will throw a traceback rather than a pretty "this is what you did wrong" explanation when adding foreign keys manually.

There's been an error:

Traceback (most recent call last):

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/handlers/base.py", line 63, in get_response
    return callback(request, **param_dict)

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/views/admin/main.py", line 860, in change_stage
    new_object = manipulator.save(new_data)

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/meta.py", line 87, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/meta.py", line 1479, in manipulator_save
    new_rel_obj.save()

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/meta.py", line 87, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/meta.py", line 765, in method_save
    (opts.db_table, ','.join(field_names), ','.join(placeholders)), db_values)

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/db/base.py", line 10, in execute
    result = self.cursor.execute(sql, params)

IntegrityError: ERROR:  null value in column "votes" violates not-null constraint

INSERT INTO polls_choices (poll_id,choice,votes) VALUES ('1','This is making me hungry ;-)',NULL)

Attachments (0)

Change History (3)

comment:1 Changed 9 years ago by adrian

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

It's your responsibility to add blank=True to a field that has null=True if you want the admin to complain about blank values.

comment:2 Changed 9 years ago by marcink

  • Resolution invalid deleted
  • Status changed from closed to reopened

Could we change the tutorial to contain either the 'blank=True' parameter or a warning that this will happen? The stack trace does not look like it was there by design and spoils the first impression a bit.

comment:3 Changed 7 years ago by gwilson

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

There is now a note in the model-api docs that describes what blank=True does.

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.