﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29649	admin readonly_fields with unique_together raises IntegrityError	Harm Verhagen	nobody	"I'm getting an IntegrityError when editing a model in the admin, when one of the fields of a unique_together pair is in readonly_fields

=== example
{{{
#models.py
class Foo(models.Model):
    a = models.IntegerField()
    b = models.IntegerField()

    class Meta:
        unique_together = (('a', 'b'), )

#admin.py
class FooAdmin(admin.ModelAdmin):
    list_display = ('id', 'a', 'b')
    readonly_fields = ('b', )
}}}



=== steps to reproduce

In django shell create two instances
{{{
>>> from data.models import Foo
>>> Foo.objects.create(a=1,b=1)
<Foo: Foo object (1)>
>>> Foo.objects.create(a=2,b=1)
<Foo: Foo object (2)>
}}}

Then in the admin edit Foo object 1 and change a to 2.  (introducing a duplicate)

=== expected result
A form validation error in the admin: {{{Foo with this A and B already exists.}}}

=== actual result
A server 500 error (IntegrityError)

{{{
IntegrityError at /admin/data/foo/3/change/
duplicate key value violates unique constraint ""data_foo_a_b_ac92595b_uniq""
DETAIL:  Key (a, b)=(1, 1) already exists.
}}}

=== notes

When removing the {{{readonly_fields}}} from the admin, all works as expected.

Maybe related to #13091  (similar issue when list_editable is used instead of readonly_fields)"	Bug	new	Uncategorized	2.0	Normal		unique_together IntegrityError		Unreviewed	0	0	0	0	0	0
