Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#20088 closed Bug (fixed)

Django admin log depends on User model having a field named id

Reported by: Ryan Leckey <leckey.ryan@…> Owned by: jcatalan
Component: contrib.admin Version: master
Severity: Normal Keywords: configurable, user, model
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no



Either we need to document that a User's pk must be named id and be integral or refactor the code linked above to not depend on it.

Change History (7)

comment:1 Changed 3 years ago by Ryan Leckey <leckey.ryan@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set

Something like the following works in my application.

def render(self, context):
    entries = LogEntry.objects.all()
    if self.user is not None:
        entries = LogEntry.objects.filter(user__exact=self.user)
    context[self.varname] = entries.select_related('content_type', 'user')[:self.limit]
    return ''

comment:2 Changed 3 years ago by aaugustin

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

I think that's the same problem as #20049.

comment:3 Changed 3 years ago by Ryan Leckey <leckey.ryan@…>

No. #20049 is about the models themselves being incapable to be acted upon if they have non-integer primary keys (I actually don't encounter that bug using mysql and InnoDB).

This issue causes Login to fail as the get_admin_log template tag is attempting to retrieve users by a relation lookup. If you change the linked code to the snippet above it works (at least in my application).

comment:4 Changed 3 years ago by aaugustin

  • Resolution duplicate deleted
  • Status changed from closed to new

Mmm, right, this could probably be fixed independently.

comment:5 Changed 3 years ago by jcatalan

  • Owner changed from nobody to jcatalan
  • Status changed from new to assigned

comment:6 Changed 3 years ago by Juan Catalano <jc@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 054ce2aa02c88221ffa5665a4b9a5739cbbd0a39:

Fixed #20088 -- Changed get_admin_log not to depend on User id field

Before this change, the get_admin_log method would expect User model's
FK to be named id. When changing that FK name, admin/index.html
rendering would fail.

This includes:

  • Changed the use of id for the use of pk property.
  • Added a regression test that fails without the patch.

This commit refs #20088.

comment:7 Changed 3 years ago by Preston Holmes <preston@…>

In 7a3409fc645c3e9c839fef08f05ec3bbcd9fb9cb:

Merge pull request #931 from catalanojuan/fix-admin-log-dependency-on-user-id-field-20088

Fixed #20088 -- Changed get_admin_log not to depend on User id field

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