Opened 15 years ago

Closed 4 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)

test11028.diff (2.2 KB ) - added by albertoconnor 9 years ago.
Patch to add a negative test case for bisecting

Download all attachments as: .zip

Change History (10)

comment:1 by Alex Gaynor, 15 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Julien Phalip, 13 years ago

Severity: Normal
Type: Bug

comment:3 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 by albertoconnor, 9 years ago

Owner: changed from nobody to albertoconnor
Status: newassigned

by albertoconnor, 9 years ago

Attachment: test11028.diff added

Patch to add a negative test case for bisecting

comment:6 by albertoconnor, 9 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 albertoconnor, 9 years ago

Resolution: fixed
Status: assignedclosed

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 Tim Graham, 9 years ago

Has patch: set
Patch needs improvement: set
Resolution: fixed
Status: closednew

Please don't close a ticket until the patch is committed.

comment:9 by Baptiste Mispelon, 4 years ago

Resolution: worksforme
Status: newclosed

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.

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