Opened 18 years ago

Closed 18 years ago

#2389 closed defect (duplicate)

admin: searching in change list causes traceback when you use column sorting

Reported by: Matthew Flanagan Owned by: Adrian Holovaty
Component: contrib.admin Version: dev
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I get the following traceback when sorting the raw_id_admin popup for the Proxy model and then entering a search term:

Traceback (most recent call last):
File "/srv/dev/mpf/nong/third-party/django/django/core/handlers/base.py" in get_response
  74. response = callback(request, *callback_args, **callback_kwargs)
File "/srv/dev/mpf/nong/third-party/django/django/contrib/admin/views/decorators.py" in _checklogin
  55. return view_func(request, *args, **kwargs)
File "/srv/dev/mpf/nong/third-party/django/django/views/decorators/cache.py" in _wrapped_view_func
  40. response = view_func(request, *args, **kwargs)
File "/srv/dev/mpf/nong/third-party/django/django/contrib/admin/views/main.py" in change_list
  739. cl = ChangeList(request, model)
File "/srv/dev/mpf/nong/third-party/django/django/contrib/admin/views/main.py" in __init__
  570. self.get_results(request)
File "/srv/dev/mpf/nong/third-party/django/django/contrib/admin/views/main.py" in get_results
  628. result_list = list(self.query_set)
File "/srv/dev/mpf/nong/third-party/django/django/db/models/query.py" in __iter__
  103. return iter(self._get_data())
File "/srv/dev/mpf/nong/third-party/django/django/db/models/query.py" in _get_data
  430. self._result_cache = list(self.iterator())
File "/srv/dev/mpf/nong/third-party/django/django/db/models/query.py" in iterator
  172. cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params)
File "/srv/dev/mpf/nong/third-party/django/django/db/backends/util.py" in execute
  12. return self.cursor.execute(sql, params)

  ProgrammingError at /admin/myapp/proxy/
  ERROR: invalid reference to FROM-clause entry for table "myapp_asset" HINT: Perhaps you meant to reference the table alias "myapp_proxy__asset". SELECT "myapp_proxy"."id","myapp_proxy"."asset_id","myapp_proxy"."port" FROM "myapp_proxy" INNER JOIN "myapp_asset" AS "myapp_proxy__asset" ON "myapp_proxy"."asset_id" = "myapp_proxy__asset"."id" WHERE ((("myapp_proxy__asset"."name" ILIKE '%foo%' OR "myapp_proxy"."port" ILIKE '%foo%'))) ORDER BY "myapp_asset"."id" ASC

The models definitions are:

from django.db import models

class Asset(models.Model):
    name = models.CharField(maxlength=16)

    def __str__(self):
        return "%s" % self.name

    class Admin:
        pass

class Proxy(models.Model):
    asset = models.ForeignKey(Asset)
    port = models.PositiveIntegerField(blank=True, null=True)

    def __str__(self):
        return "%s" % self.asset.name

    class Admin:
        list_display = ('asset', 'port')
        search_fields = ('asset__name', 'port')

class Connection(models.Model):
    asset = models.ForeignKey(Asset, editable=False, edit_inline=models.TABULAR)
    method = models.CharField(maxlength=16, core=True)
    transport = models.CharField(maxlength=16)
    proxy = models.ForeignKey(Proxy, raw_id_admin=True, blank=True, null=True)

    class Admin:
        pass

Steps to reproduce:

1) Create an Asset called "foo" and save it

2) Add a new asset called "bar" and click on the magnifying glass next to inline edited connection.

3) Add a proxy object with asset foo and port 123. This will set the proxy id in the asset add page.

4) Click on the magnifying glass again and click on the column heading "Asset" column heading.

5) enter any search term in the search input. Bang!

The same happens if you swap the order of steps 4 and 5.

Strangely enough it works ok if you sort on the port column and then search.

matthew

Change History (4)

comment:1 by anonymous, 18 years ago

Summary: admin: searching in raw_id_admin popup is tracebacks when you sort columnadmin: searching in raw_id_admin popup has traceback when you use column sort

comment:2 by mattimustang@…, 18 years ago

Summary: admin: searching in raw_id_admin popup has traceback when you use column sortadmin: searching in change list causes traceback when you use column sorting

After checking this again I found you can trigger this from the Proxy change list as well. #2520 looks like a similar bug.

comment:3 by favo@…, 18 years ago

see #2520.

comment:4 by mattimustang@…, 18 years ago

Resolution: duplicate
Status: newclosed

This is duplicate of #2520 which was fixed in [3794].

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