Re: [Django] #15665: Inline admins are broken when primary key is not an AutoField and not editable.

16 views
Skip to first unread message

Django

unread,
Jun 10, 2011, 7:45:57 AM6/10/11
to django-...@googlegroups.com
#15665: Inline admins are broken when primary key is not an AutoField and not
editable.
-------------------------------------------+-------------------------------
Reporter: sebastian_noack | Owner: nobody
Type: Bug | Status: new
Milestone: | Component: contrib.admin
Version: 1.2 | Severity: Normal
Resolution: | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+-------------------------------
Changes (by dArignac):

* ui_ux: => 0
* easy: => 0


Comment:

Looks like an duplicate of #13696

--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 9, 2015, 6:49:16 PM10/9/15
to django-...@googlegroups.com
#15665: Inline admins are broken when primary key is not an AutoField and not
editable.
---------------------------------+------------------------------------

Reporter: sebastian_noack | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by timgraham):

This remains an issue as of 7a5b7e35bf2e219225b9f26d3dd3e34f26e83e9c
(Django 1.10.dev).

--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:8>

Django

unread,
Jun 20, 2016, 2:29:50 PM6/20/16
to django-...@googlegroups.com
#15665: Inline admins are broken when primary key is not an AutoField and not
editable.
---------------------------------+------------------------------------
Reporter: sebastian_noack | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by olivierdalang):

* cc: olivier.dalang@… (added)


Comment:

I agree it's kind of tricky when the user can change the ID (as expeced
behaviour is not clear), but the issue also happens in a very normal case,
simply when one is using UUIDs instead of regular autoincremented IDs :

{{{
#!python
from django.db import models
import uuid

class Event( models.Model ):
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
name = models.CharField(max_length=10, blank=False)

def __str__(self):
return self.name

class Person( models.Model ):
id = models.UUIDField(primary_key=True, default=uuid.uuid4)
parent = models.ForeignKey('Event', null=True, blank=True,
related_name='children')
name = models.CharField(max_length=10, blank=True)

def __str__(self):
return self.name

class Visitor(Person):
pass
}}}

{{{
#!python
from django.contrib import admin
from .models import Event, Visitor

class VisitorInline( admin.TabularInline ):
model = Visitor
show_change_link = True


class EventAdmin( admin.ModelAdmin ):
inlines = [VisitorInline,]


admin.site.register(Event, EventAdmin)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:9>

Django

unread,
Jun 20, 2016, 7:04:58 PM6/20/16
to django-...@googlegroups.com
#15665: Inline admins are broken when primary key is not an AutoField and not
editable.
---------------------------------+------------------------------------
Reporter: sebastian_noack | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by olivierdalang):

* has_patch: 0 => 1
* needs_tests: 0 => 1


Comment:

I had a look at the source. I see two places where this can be fixed :

A. in django/db/models/base.py

Model inheritance is created using OneToOneField but doesn't set the field
to editable=False.
This seems wrong, but at the same time, it seem to be consistent with
regular primary keys, that for some reason don't set editable=False
neither.
The fix consists of settings editable=False on those fields.
I'm not sure of the consequences of this, but this breaks potentially a
lot of things.

https://github.com/olivierdalang/django/commit/a4ea0a021b784c5fbbecebed01f86c3987f1a8e9

B. in django/contrib/admin/helpers.py

There's a needs_explicit_pk_field() method which is exactly for that.
The fix B consists of return True if the primary key is a OneToOneField.
I guess this has much less consequences and is much safer.

https://github.com/olivierdalang/django/commit/fed7cd7f73f06a26f8a2eb8e867bdf4c81d4ae00


What do you think ? For which fix should I open a PR ? Is there any chance
this gets backported to 1.9 ?

--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:10>

Django

unread,
Jul 22, 2016, 6:05:33 PM7/22/16
to django-...@googlegroups.com
#15665: Inline admins are broken when primary key is not an AutoField and not
editable.
---------------------------------+------------------------------------
Reporter: sebastian_noack | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by timgraham):

I closed #26934 as a duplicate.

--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:11>

Django

unread,
Jul 22, 2016, 6:06:21 PM7/22/16
to django-...@googlegroups.com
#15665: Inline admins are broken when primary key is not an AutoField and not
editable.
---------------------------------+------------------------------------
Reporter: sebastian_noack | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by timgraham):

* needs_tests: 1 => 0


Comment:

[https://github.com/django/django/pull/6818 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:12>

Django

unread,
Aug 17, 2016, 4:13:03 PM8/17/16
to django-...@googlegroups.com
#15665: Inline admins are broken when primary key is not an AutoField and not
editable.
---------------------------------+------------------------------------
Reporter: sebastian_noack | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:13>

Django

unread,
Oct 13, 2016, 5:15:06 PM10/13/16
to django-...@googlegroups.com
#15665: Inline admins are broken when primary key is not an AutoField and not
editable.
---------------------------------+------------------------------------
Reporter: Sebastian Noack | Owner: nobody

Type: Bug | Status: new
Component: contrib.admin | Version: 1.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 1 => 0


Comment:

[https://github.com/django/django/pull/7365 New PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:14>

Django

unread,
Nov 15, 2016, 11:02:23 AM11/15/16
to django-...@googlegroups.com
#15665: Inline admins are broken when primary key is not an AutoField and not
editable.
---------------------------------+------------------------------------
Reporter: Sebastian Noack | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


Comment:

As noted on the PR, the fix allows data corruption in some cases.

--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:15>

Django

unread,
Nov 6, 2017, 8:35:07 AM11/6/17
to django-...@googlegroups.com
#15665: Inline admins are broken when primary key is not an AutoField and not
editable.
---------------------------------+------------------------------------
Reporter: Sebastian Noack | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Andi Albrecht):

* cc: Andi Albrecht (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:16>

Django

unread,
Jan 15, 2019, 12:07:05 PM1/15/19
to django-...@googlegroups.com
#15665: Inline admins are broken when primary key is not an AutoField and not
editable.
---------------------------------+------------------------------------
Reporter: Sebastian Noack | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by Olivier):

I think this is a duplicate of https://code.djangoproject.com/ticket/27967
(which is fixed)

--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:17>

Django

unread,
Jan 15, 2019, 1:07:03 PM1/15/19
to django-...@googlegroups.com
#15665: Inline admins are broken when primary key is not an AutoField and not
editable.
---------------------------------+-------------------------------------

Reporter: Sebastian Noack | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.2
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
---------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => duplicate


--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:18>

Reply all
Reply to author
Forward
0 new messages