Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#20049 closed Bug (needsinfo)

Admin incompatible with non-integer primary keys

Reported by: aaugustin Owned by: nobody
Component: contrib.admin Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Since the admin log uses a GFK with an integer object_id, creating, modifying or deleting an object with a non-integer primary key fails.

For instance, it's impossible to edit the following model in the admin:

from django.db import models

class Release(models.Model):
    version = models.CharField(max_length=16, primary_key=True)

Change History (7)

comment:1 Changed 3 years ago by aaugustin

As a workaround, one can disable logging by adding these lines to the ModelAdmin class:

def log_addition(self, request, object): pass
def log_change(self, request, object): pass
def log_deletion(self, request, object): pass

comment:2 Changed 3 years ago by jacob

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 3 years ago by lakshman@…

I just tested this on the development version and it seems to work fine.

comment:4 Changed 3 years ago by aaugustin

Have you tested with a database that enforces types, ie. not SQLite?

On SQLite Django happily saves a string in an integer field and the bug doesn't appear.

comment:5 Changed 3 years ago by aaugustin

#20088 reported this problem with a custom user model.

comment:6 Changed 3 years ago by claudep

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

I don't doubt there are issues with non-integer PKs, but we still miss failure data. LogEntry.object_id is a TextField, so this is not the culprit. And I could add and delete an object with a non-integer primary key with Postgres.

comment:7 Changed 3 years ago by claudep

The issue might be rather #20088 (which is now fixed).

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