Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#20049 closed Bug (needsinfo)

Admin incompatible with non-integer primary keys

Reported by: Aymeric Augustin 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

Description

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 by Aymeric Augustin, 12 years ago

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 by Jacob, 12 years ago

Triage Stage: UnreviewedAccepted

comment:3 by lakshman@…, 12 years ago

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

comment:4 by Aymeric Augustin, 12 years ago

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 by Aymeric Augustin, 12 years ago

#20088 reported this problem with a custom user model.

comment:6 by Claude Paroz, 11 years ago

Resolution: needsinfo
Status: newclosed

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 by Claude Paroz, 11 years ago

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

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