Opened 4 months ago

Closed 3 months ago

#37122 closed Bug (fixed)

JSONField has_changed doesn't reflect disabled correctly

Reported by: alex Owned by: Frick Wu
Component: Forms Version: 6.0
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by alex)

Problem:

A disabled JSONField still reports changes via has_changed.

Why?

def has_changed(self, initial, data):
    # here we miss the check for disabled
    if super().has_changed(initial, data):
        return True
    ...

As we see, has_changed from the base is called and if successful, True is returned. But we have no additional check for disabled.

Fix:

def has_changed(self, initial, data):
    if self.disabled:
        return False
    if super().has_changed(initial, data):
        return True
    ...

This corrupts the changed fields in the history of admin (disabled JSONFields are always shown as changed).

Change History (13)

comment:1 by alex, 4 months ago

Description: modified (diff)

comment:2 by alex, 4 months ago

Description: modified (diff)

comment:3 by alex, 4 months ago

Despite being mostly just informational there is a danger:

it can lead to serious work problems if people check the history of an object and wrongly accuse employees to change values they aren't allowed change or even hack their system.

Version 0, edited 4 months ago by alex (next)

comment:4 by Simon Charette, 4 months ago

Component: Uncategorized → Forms
Has patch: unset
Triage Stage: Unreviewed → Accepted
Type: Uncategorized → Bug

There's effectively a bug here based on how forms.Field.has_changed ​is implemented.

Would you be willing to ​submit a patch? Looks like a simple test could be added ​around here.

comment:5 by Vaibhav Pant, 4 months ago

Owner: set to Vaibhav Pant
Status: new → assigned

comment:6 by Simon Charette, 4 months ago

Owner: Vaibhav Pant removed
Status: assigned → new

Vaibhav please give the reporter the chance to answer before claiming the ticket.

comment:7 by Frick Wu, 4 months ago

Hi I would like to claim and work on this ticket, how do i go about doing that? I tried following the Claim a ticket instructions but cant seem to make it work.

comment:8 by Jacob Walls, 4 months ago

Owner: set to Jacob Walls
Status: new → assigned

Sure thing. Use Modify Ticket button, click "assign to" radio button, set your username, Submit changes.

comment:9 by Jacob Walls, 4 months ago

Owner: Jacob Walls removed
Status: assigned → new

comment:10 by Frick Wu, 4 months ago

Owner: set to Frick Wu
Status: new → assigned

comment:11 by Frick Wu, 4 months ago

Has patch: set

comment:12 by Simon Charette, 4 months ago

Triage Stage: Accepted → Ready for checkin

Patch LGTM

comment:13 by Sarah Boyce <42296566+sarahboyce@…>, 3 months ago

Resolution: → fixed
Status: assigned → closed

In e26cdc5:

Fixed #37122 -- Updated JSONField has_changed method to check for disabled status.

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