#17034: 'Invalid literal for int' using admin site called with invalid 
parameters
for inherited models
-------------------------------------+-------------------------------------
     Reporter:  ralphje              |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  contrib.admin        |                  Version:  1.3
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Design
    Has patch:  0                    |  decision needed
  Needs tests:  0                    |      Needs documentation:  0
Easy pickings:  0                    |  Patch needs improvement:  0
                                     |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by julien):

 * needs_docs:   => 0
 * stage:  Unreviewed => Design decision needed
 * needs_tests:   => 0
 * needs_better_patch:   => 0


Comment:

 I could verify this issue. As far as the admin is concerned, this is
 happening in the `get_object()` method:
 
https://code.djangoproject.com/browser/django/trunk/django/contrib/admin/options.py?rev=16934#L475

 In that method, the object_id is initially prepared by doing:

 {{#!python
 object_id = model._meta.pk.to_python(object_id)
 }}}

 In the case of a "normal" model (without inheritance), the pk field is an
 `AutoField` and therefore the line above raises a `ValidationError`. Then,
 `get_object()` catches the error, ignores it, and moves on peacefully. So
 eventually a 404 page is returned.

 However, in the case of a "complex" model (using inheritance), the pk is a
 `OneToOneField`, whose `to_python()` method simply returns the value
 ('blahblah') unchanged without raising any exception. That value is then
 used in `queryset.get(pk=object_id)`, which raises a `ValueError`, which
 isn't caught by `get_object()`.

 The question is, should a `ValidationError` be returned by `OneToOneField`
 (or any `ForeignKey`) when a value with unexpected format is provided to
 `to_python()`, or should the admin's `get_object()` silently catch and
 ignore `ValueError`?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/17034#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to