#30006 closed Bug (duplicate)

Wrong UUID serialization in inline admin when used as a 1to1Field primary key of a UUID primary key.

Reported by: George Cheng Owned by: nobody
Component: Database layer (models, ORM) Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Sorry for the confusing title, I create a reproducing repo on GitHub.

Key code as follows:


class Room(models.Model):
    id = models.UUIDField(default=uuid4, primary_key=True, editable=False)
    name = models.TextField()

    def __str__(self):
        return self.name

class Teacher(models.Model):
    room = models.OneToOneField(Room, on_delete=models.CASCADE,
    name = models.TextField()

    def __str__(self):
        return self.name

class Student(models.Model):
    id = models.UUIDField(default=uuid4, primary_key=True, editable=False)
    teacher = models.ForeignKey(Teacher, on_delete=models.CASCADE)
    name = models.TextField()

    def __str__(self):
        return self.name


from .models import Room, Teacher, Student

class RoomAdmin(admin.ModelAdmin):

class TeacherAdmin(admin.ModelAdmin):
    class StudentInline(admin.TabularInline):
        model = Student

    inlines = [StudentInline]

Change History (3)

comment:1 Changed 11 months ago by George Cheng

Found a workaround: add readonly_fields = ('teachers',) to student inline works.

comment:2 Changed 11 months ago by George Cheng

>>> from app.models import *
>>> Teacher.objects.last().room_id
>>> Student.objects.last().teacher_id

They are all UUIDs

comment:3 Changed 11 months ago by Simon Charette

Component: contrib.adminDatabase layer (models, ORM)
Resolution: duplicate
Status: newclosed

Duplicate of #27595 which will be fixed in Django 2.2.

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