Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#33871 closed Bug (duplicate)

JSONField with default is not detected as changed when invalidated in inlines.

Reported by: Raphael Owned by: JunKi Yoon
Component: Forms Version: 4.0
Severity: Normal Keywords: JSONField TabularInline
Cc: Carlton Gibson Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by Raphael)

Apparently the JSONField field modification in a TabularInline is ignored after a validation error.

To reproduce I attached the generated project based of the basic Django tutorial with changes to use a JSONField and TabularInline

user: admin
password: admin

Sequence:

  1. Edit the Question
  2. Change both Text field to "test"
  3. Change both JsonField to 'test' (Any Valid Json)
  4. Save
  5. Edit again
  6. Change both two JsonField to 'test 123' (Any Valid Json)
  7. Delete text from Text field of the second item
  8. Save
  9. Error message will appear
  10. Set the Choice Text field to 'test 123' of the second item
  11. Save
  12. Edit again, only the second JsonField was changed to 'test 123' (Any Valid Json)

Attachments (1)

djangoInlineBug.zip (22.6 KB ) - added by Raphael 2 years ago.

Download all attachments as: .zip

Change History (17)

by Raphael, 2 years ago

Attachment: djangoInlineBug.zip added

comment:1 by Raphael, 2 years ago

Type: UncategorizedBug

comment:2 by Raphael, 2 years ago

Description: modified (diff)

comment:3 by Raphael, 2 years ago

Description: modified (diff)

comment:4 by Raphael, 2 years ago

Description: modified (diff)

comment:5 by Mariusz Felisiak, 2 years ago

Cc: Carlton Gibson added
Component: contrib.adminForms
Severity: Release blockerNormal
Summary: Bug that occurs when using JSONField and TabularInlineJSONField with default is not detected as changed when invalidated in inlines.
Triage Stage: UnreviewedAccepted

Thanks for the detailed report. initial value is set to a new value when invalidated, that's why changes are not detected:

choice_set-0-test="test 123"
initial-choice_set-0-test="test 123"

in reply to:  5 ; comment:6 by JunKi Yoon, 2 years ago

Replying to Mariusz Felisiak:

Is this still a bug that needs to be fixed?

in reply to:  6 ; comment:7 by Mariusz Felisiak, 2 years ago

Replying to JunKi Yoon:

Is this still a bug that needs to be fixed?

Yes, it's waiting for a patch.

in reply to:  7 comment:8 by JunKi Yoon, 2 years ago

Owner: changed from nobody to JunKi Yoon
Status: newassigned

Replying to Mariusz Felisiak:

Ok, I will try. Thank you for reply :)

in reply to:  description ; comment:9 by JunKi Yoon, 2 years ago

Replying to Raphael, Mariusz Felisiak:

Hi, Raphael. I want to patch this issue.

  1. So, Could you plz give me the URL for the basic Django tutorial ?
  1. And, I downloaded your attachments. I have a question about sequence you wrote. Did you run it from the admin page ? or Django shell ?
  1. Did you mean, right?
    two TextField -> Question.question_text, Choice.choice_text,
    one JsonField -> Choice.test 
    

How can I reproduce ?

Last edited 2 years ago by JunKi Yoon (previous) (diff)

in reply to:  9 comment:10 by Raphael, 2 years ago

Hello,

  1. So, Could you plz give me the URL for the basic Django tutorial ?

--- https://docs.djangoproject.com/en/4.1/intro/tutorial01/

  1. And, I downloaded your attachments. I have a question about sequence you wrote. Did you run it from the admin page ? or Django shell ?

-- Admin page

  1. Did you mean, right?

-- I didn't really understand the question, but in the sample I attached is another field. I don't think this is relevant to the problem. I think it's easier for you to use the sample I sent.

How can I reproduce ?

Run the code and follow the Sequence. You will see that the data will not be store correctly.

Thank you.

Replying to JunKi Yoon:

Replying to Raphael, Mariusz Felisiak:

Hi, Raphael. I want to patch this issue.

  1. So, Could you plz give me the URL for the basic Django tutorial ?
  1. And, I downloaded your attachments. I have a question about sequence you wrote. Did you run it from the admin page ? or Django shell ?
  1. Did you mean, right?
    two TextField -> Question.question_text, Choice.choice_text,
    one JsonField -> Choice.test 
    

How can I reproduce ?

in reply to:  5 comment:11 by JunKi Yoon, 2 years ago

Replying to Mariusz Felisiak:

Hi Mariusz Felisiak :)

After debugging, I confirmed that the initial-choice_set-0-test and choice_set-0-test are same. (same initial-choice_set-0-test, choice_set-1-test)
And then, They don't have changed_data. That's why the issue.

So, I guess one thing. initial-choice_set-0-test is not the value that the Choice object currently has.
initial-choice_set-0-test value after showing error message by sequence 8 is stored as the input value in sequence 6.

Could you plz give me some advice regarding where to set the initial-XXX-XXX and code?

Thank you.

cc) Raphael

Thanks for the detailed report. initial value is set to a new value when invalidated, that's why changes are not detected:

choice_set-0-test="test 123"
initial-choice_set-0-test="test 123"
Last edited 2 years ago by JunKi Yoon (previous) (diff)

comment:12 by Jacob Walls, 2 years ago

Has patch: set

comment:13 by Carlton Gibson, 2 years ago

Patch needs improvement: set

Current patch is mixing solution between forms and admin components. Slightly clearer tests showing the problem would probably clarify.

in reply to:  13 comment:14 by JunKi Yoon, 2 years ago

Replying to Carlton Gibson:

Current patch is mixing solution between forms and admin components. Slightly clearer tests showing the problem would probably clarify.

I Improved patch and tests. :)

comment:15 by Mariusz Felisiak, 2 years ago

Resolution: duplicate
Status: assignedclosed
Triage Stage: AcceptedUnreviewed

Duplicate of #34119.

comment:16 by David Sanders, 2 years ago

Confirmed the patch for #34119 fixes the issue with sample models provided and steps described above.

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