Opened 16 years ago
Closed 5 years ago
#11028 closed Bug (worksforme)
Problem with searching in m2m fields in inherited model
Reported by: | Vitek Pliska | Owned by: | albertoconnor |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | admin search inheritance |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Models:
class Publishable(models.Model): ... authors = models.ManyToManyField(Author, verbose_name=_('Authors')) class Article(Publishable): ...
and admin options like these:
class PublishableAdmin(admin.ModelAdmin): ... search_fields = ('title', 'description', 'slug', 'authors__name', 'authors__slug',) class ArticleAdmin(PublishableAdmin): ...
Now, if we try search articles in admin, got this error:
ProgrammingError at /newman/articles/article/ invalid reference to FROM-clause entry for table "core_publishable" LINE 1: ...") LEFT OUTER JOIN "core_publishable_authors" ON ("core_publ... ^ HINT: Perhaps you meant to reference the table alias "t3".
Attachments (1)
Change History (10)
comment:1 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:3 by , 13 years ago
UI/UX: | unset |
---|
comment:5 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:6 by , 10 years ago
bisecting showed that the issue was fixed in cf70c96ce08bec8834ada695451cc915f7558dbd.
It isn't clear if there is a regression test in that commit, it is possible another test catches it though.
comment:7 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Since I was unable to find a regression test I added a test in PR: https://github.com/django/django/pull/4517.
comment:8 by , 10 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
Resolution: | fixed |
Status: | closed → new |
Please don't close a ticket until the patch is committed.
comment:9 by , 5 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
I haven't been able to reproduce the initial issue.
I tried with the following models/modeladmins:
class Author(models.Model): name = models.CharField(max_length=200, default='<name>') slug = models.SlugField() class Publishable(models.Model): title = models.CharField(max_length=50, default='<title>') slug = models.SlugField() description = models.CharField(max_length=200, default='<description>') authors = models.ManyToManyField(Author, verbose_name=('Authors')) class Article(Publishable): pass class PublishableAdmin(admin.ModelAdmin): search_fields = ('authors__name', 'authors__slug',) class ArticleAdmin(PublishableAdmin): pass
(Because the initial report wasn't very clear, I even tried making Publishable
an abstract model but that didn't seem to change anything).
With this setup, I would start runserver
, navigate to the Article
admin and start a search, expecting to see the reported error.
I tried various versions of Django (including all tagged 1.0.X releases since 1.0 was the latest release at the time of the report) but I could never trigger any error while doing a search.
The testcase that's attached earlier in the ticket doesn't actually track this issue. It uses self.assertRaises(Exception)
which is too broad and ends up catching an AttributeError
on m.list_max_show_all
just before that attribute is introduced (which explains why it uncovers cf70c96ce08bec8834ada695451cc915f7558dbd).
Given this and the fact that this ticket has seen very little activity over the years, I'm going to close it.
Change UI/UX from NULL to False.