Opened 3 weeks ago

Last modified 2 weeks ago

#37122 assigned Bug

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 (12)

comment:1 by alex, 3 weeks ago

Description: modified (diff)

comment:2 by alex, 3 weeks ago

Description: modified (diff)

comment:3 by alex, 3 weeks 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.

So please inform in the changelog prominently that disabled JSONFields may appear to have been changed.

Last edited 3 weeks ago by alex (previous) (diff)

comment:4 by Simon Charette, 3 weeks ago

Component: UncategorizedForms
Has patch: unset
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

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, 3 weeks ago

Owner: set to Vaibhav Pant
Status: newassigned

comment:6 by Simon Charette, 3 weeks ago

Owner: Vaibhav Pant removed
Status: assignednew

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

comment:7 by Frick Wu, 3 weeks 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, 3 weeks ago

Owner: set to Jacob Walls
Status: newassigned

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

comment:9 by Jacob Walls, 3 weeks ago

Owner: Jacob Walls removed
Status: assignednew

comment:10 by Frick Wu, 3 weeks ago

Owner: set to Frick Wu
Status: newassigned

comment:11 by Frick Wu, 3 weeks ago

Has patch: set

comment:12 by Simon Charette, 2 weeks ago

Triage Stage: AcceptedReady for checkin

Patch LGTM

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