[Django] #28589: When saving in admin, readonly fields are saved again

30 views
Skip to first unread message

Django

unread,
Sep 12, 2017, 6:46:48 AM9/12/17
to django-...@googlegroups.com
#28589: When saving in admin, readonly fields are saved again
-------------------------------------+-------------------------------------
Reporter: FingalP | Owner: nobody
Type: Bug | Status: new
Component: | Version: master
contrib.admin |
Severity: Normal | Keywords: Admin SQL Overwrite
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
On the admin page for a model, if a field is in readonly_fields, then
saving that model from the admin will create an SQL query that sets the
readonly field to it's value at the time the save button was clicked. This
field might have been changed (e.g. by a command or some other process)
during the time that the model is being saved, and with current behaviour
it would then be overwritten to it's old value.

Correct behaviour would be to not set the readonly field at all in the SQL
query.

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

Django

unread,
Sep 12, 2017, 6:47:46 AM9/12/17
to django-...@googlegroups.com
#28589: When saving in admin, readonly fields are saved again
-------------------------------------+-------------------------------------
Reporter: FingalP | Owner: FingalP
Type: Bug | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

Keywords: Admin SQL Overwrite | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by FingalP):

* status: new => assigned
* owner: nobody => FingalP


--
Ticket URL: <https://code.djangoproject.com/ticket/28589#comment:1>

Django

unread,
Sep 12, 2017, 6:54:58 AM9/12/17
to django-...@googlegroups.com
#28589: When saving in admin, readonly fields are potentially overwritten

-------------------------------------+-------------------------------------
Reporter: FingalP | Owner: FingalP
Type: Bug | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: Admin SQL Overwrite | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/28589#comment:2>

Django

unread,
Sep 12, 2017, 6:59:13 AM9/12/17
to django-...@googlegroups.com
#28589: When saving in admin, readonly fields are potentially overwritten
-------------------------------------+-------------------------------------
Reporter: FingalP | Owner: FingalP
Type: Bug | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: Admin SQL Overwrite | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by FingalP:

Old description:

> On the admin page for a model, if a field is in readonly_fields, then
> saving that model from the admin will create an SQL query that sets the
> readonly field to it's value at the time the save button was clicked.
> This field might have been changed (e.g. by a command or some other
> process) during the time that the model is being saved, and with current
> behaviour it would then be overwritten to it's old value.
>
> Correct behaviour would be to not set the readonly field at all in the
> SQL query.

New description:

On the admin page for a model, if a field is in readonly_fields or has
editable=False, then saving that model from the admin will create an SQL


query that sets the readonly field to it's value at the time the save
button was clicked. This field might have been changed (e.g. by a command
or some other process) during the time that the model is being saved, and
with current behaviour it would then be overwritten to it's old value.

Correct behaviour would be to not set the readonly field at all in the SQL
query.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/28589#comment:3>

Django

unread,
Sep 12, 2017, 7:43:05 AM9/12/17
to django-...@googlegroups.com
#28589: When saving in admin, readonly fields are potentially overwritten
-------------------------------------+-------------------------------------
Reporter: FingalP | Owner: FingalP
Type: Bug | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: Admin SQL Overwrite | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by FingalP:

Old description:

> On the admin page for a model, if a field is in readonly_fields or has
> editable=False, then saving that model from the admin will create an SQL


> query that sets the readonly field to it's value at the time the save
> button was clicked. This field might have been changed (e.g. by a command
> or some other process) during the time that the model is being saved, and
> with current behaviour it would then be overwritten to it's old value.
>
> Correct behaviour would be to not set the readonly field at all in the
> SQL query.

New description:

On the admin page for a model, if a field is in readonly_fields or has
editable=False, then saving that model from the admin will create an SQL


query that sets the readonly field to it's value at the time the save
button was clicked. This field might have been changed (e.g. by a command
or some other process) during the time that the model is being saved, and
with current behaviour it would then be overwritten to it's old value.

Correct behaviour would be to not set the readonly/uneditable field at all
in the SQL query.

The exception to this is a DateTimeField with auto_now or auto_now_add,
which have editable=False but should be updated when the SQL query is
made.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/28589#comment:4>

Django

unread,
Sep 12, 2017, 8:06:52 AM9/12/17
to django-...@googlegroups.com
#28589: When saving in admin, readonly fields are potentially overwritten
-------------------------------------+-------------------------------------
Reporter: FingalP | Owner: FingalP
Type: Bug | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: Admin SQL Overwrite | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by FingalP):

My patch is available at branch ticket_28589 of my fork of Django
https://github.com/FingalP/django

--
Ticket URL: <https://code.djangoproject.com/ticket/28589#comment:5>

Django

unread,
Sep 28, 2017, 2:05:37 PM9/28/17
to django-...@googlegroups.com
#28589: When saving in admin, readonly fields are potentially overwritten
-------------------------------------+-------------------------------------
Reporter: Fingal Plumpton | Owner: Fingal
Type: | Plumpton
Cleanup/optimization | Status: assigned

Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: Admin SQL Overwrite | 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
* type: Bug => Cleanup/optimization
* easy: 1 => 0
* stage: Unreviewed => Accepted


Comment:

Recently, someone raised [https://groups.google.com/d/topic/django-
users/oYYqT7SIJVg/discussion a similar issue for model forms]. I think the
problem should be solved at that level first. Perhaps that'll help
simplify the code at the admin level -- the current code looks too
complicated.

--
Ticket URL: <https://code.djangoproject.com/ticket/28589#comment:6>

Django

unread,
Jan 14, 2024, 10:58:18 PM1/14/24
to django-...@googlegroups.com
#28589: When saving in admin, readonly fields are potentially overwritten
-------------------------------------+-------------------------------------
Reporter: Fingal Plumpton | Owner: Fingal
Type: | Plumpton
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev

Severity: Normal | Resolution:
Keywords: Admin SQL Overwrite | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Alexander Lazarević):

So for what it's worth, this seems to be still the case in
5.1.dev20240112204018:

{{{
UPDATE "empty_somemodel"
SET "name" = '''wowzer'',
"description" = '''''',
"choices" = '''''',
"random_tag" = '''9436''',
"date" = '''2024-01-01''',
"time" = '''11:18:48''',
"boolean" = 'False',
"decimal" = '''0.01''',
"floating" = '1.0',
"json" = '''{}'''
WHERE "empty_somemodel"."id" = '1'
}}}

{{{
class SomeModel(models.Model):
...
random_tag = models.CharField(null=False, max_length=32,
default=random_text, editable=False)
...
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28589#comment:7>

Reply all
Reply to author
Forward
0 new messages