Code

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#11678 closed (duplicate)

ValueError when passing an extra parameter in URL

Reported by: kberkhout Owned by: nobody
Component: contrib.admin Version: 1.1
Severity: Keywords: ValueError, django.contrib.admin
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Django.contrib.admin produces a ValueError when passing an extra parameter to the URL.
Example:
The edit page for the model 'deelnemer' is: http://localhost:8000/admin/aanmelden/deelnemer/1/
When typing an extra 'a' behind the url (http://localhost:8000/admin/aanmelden/deelnemer/1/a/) a ValueError occurs

Wouldn't it be better for production environments to produce a 404?

Traceback:

Environment:

Request Method: GET
Request URL: http://localhost:8000/admin/aanmelden/deelnemer/1/a/
Django Version: 1.1
Python Version: 2.5.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.admin',
 'skievent.aanmelden']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/Library/Python/2.5/site-packages/django/core/handlers/base.py" in get_response
  92.                 response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.5/site-packages/django/contrib/admin/sites.py" in root
  490.                 return self.model_page(request, *url.split('/', 2))
File "/Library/Python/2.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/Library/Python/2.5/site-packages/django/contrib/admin/sites.py" in model_page
  509.         return admin_obj(request, rest_of_url)
File "/Library/Python/2.5/site-packages/django/contrib/admin/options.py" in __call__
  1098.             return self.change_view(request, unquote(url))
File "/Library/Python/2.5/site-packages/django/db/transaction.py" in _commit_on_success
  240.                 res = func(*args, **kw)
File "/Library/Python/2.5/site-packages/django/contrib/admin/options.py" in change_view
  793.             obj = self.queryset(request).get(pk=unquote(object_id))
File "/Library/Python/2.5/site-packages/django/db/models/query.py" in get
  299.         clone = self.filter(*args, **kwargs)
File "/Library/Python/2.5/site-packages/django/db/models/query.py" in filter
  498.         return self._filter_or_exclude(False, *args, **kwargs)
File "/Library/Python/2.5/site-packages/django/db/models/query.py" in _filter_or_exclude
  516.             clone.query.add_q(Q(*args, **kwargs))
File "/Library/Python/2.5/site-packages/django/db/models/sql/query.py" in add_q
  1675.                             can_reuse=used_aliases)
File "/Library/Python/2.5/site-packages/django/db/models/sql/query.py" in add_filter
  1614.                 connector)
File "/Library/Python/2.5/site-packages/django/db/models/sql/where.py" in add
  56.                 obj, params = obj.process(lookup_type, value)
File "/Library/Python/2.5/site-packages/django/db/models/sql/where.py" in process
  269.                 params = self.field.get_db_prep_lookup(lookup_type, value)
File "/Library/Python/2.5/site-packages/django/db/models/fields/__init__.py" in get_db_prep_lookup
  210.             return [self.get_db_prep_value(value)]
File "/Library/Python/2.5/site-packages/django/db/models/fields/__init__.py" in get_db_prep_value
  361.         return int(value)

Exception Type: ValueError at /admin/aanmelden/deelnemer/1/a/
Exception Value: invalid literal for int() with base 10: '1/a'

Thanks,

Kevin

Attachments (0)

Change History (5)

comment:1 Changed 5 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

#3785 is already open for this general problem.

comment:2 Changed 5 years ago by mr.kschan@…

  • Resolution duplicate deleted
  • Status changed from closed to reopened

this may not be a duplicate for #3785.

as some of the auto-complete widgets for ForeginKeyField are using url like "/app/model/search..."
in which the url is responded by ModelAdmin's call as follow.

# forward request by url
def __call__(self, request, url):
    if url is None:
        pass
    elif url == 'search':
        return auto_complete(request)
    return super(MyModelAdmin, self).__call__(request, url)

In Django 1.0.2, this works fine with the call request forward. But in 1.1, above exception raised.

comment:3 follow-up: Changed 5 years ago by Alex

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

What you've just said is orthagonal to the problem the reporter hsa. If you believe there is a different bug please file a new ticket, this one is a duplicate.

comment:4 in reply to: ↑ 3 ; follow-up: Changed 5 years ago by mr.kschan@…

Replying to Alex:

What you've just said is orthagonal to the problem the reporter hsa. If you believe there is a different bug please file a new ticket, this one is a duplicate.

Ok, I just fixed how Django1.1 forward urls ... using the new get_urls(self) documented on http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-methods

The old codes should be updated to use get_urls instead of call like...

def get_urls(self):
    from django.conf.urls.defaults import *

    urls = super(MyModelAdmin, self).get_urls()
    my_urls = patterns('',
        (r'search', auto_complete),
    )
    return my_urls + urls

comment:5 in reply to: ↑ 4 Changed 5 years ago by kmtracey

Replying to mr.kschan@gmail.com:

Please open a new ticket for this problem rather than continuing to post snippets of info and fix possibilities here. Posting such information to closed tickets is likely going to result in the information getting lost. A new ticket that fully describes the problem and how to recreate it, with a proper patch, would be much more useful.

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.