* 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.
Comment (by timgraham):
This remains an issue as of 7a5b7e35bf2e219225b9f26d3dd3e34f26e83e9c
(Django 1.10.dev).
--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:8>
* 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>
* 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>
Comment (by timgraham):
I closed #26934 as a duplicate.
--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:11>
* needs_tests: 1 => 0
Comment:
[https://github.com/django/django/pull/6818 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:12>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:13>
* 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>
* 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>
* cc: Andi Albrecht (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:16>
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>
* status: new => closed
* resolution: => duplicate
--
Ticket URL: <https://code.djangoproject.com/ticket/15665#comment:18>