Inconsistent form build between initial form generation and the first ajax request

Created on 2 November 2016, about 8 years ago
Updated 11 December 2023, 12 months ago

Problem/Motivation

#2502785: Remove support for $form_state->setCached() for GET requests β†’ caused forms not be cached for get requests which has led to the following problem that the form might get rebuild with different entity revisions.

  1. Create an entity.
  2. Load the entity edit form - the entity form is build with the entity in revision 1.
  3. Save the entity in the background in a new revision - revision id 2.
  4. Trigger an ajax request causing form rebuild e.g. "Add another item" - the entity form is rebuild with the entity in revision 2.<
  5. Save the entity in the background in a new revision - revision id 3.
  6. Trigger an ajax request causing form rebuild e.g. "Add another item" - the entity form is rebuild with the entity in revision 2.<

Additionally there might occur different problem:

  1. Create an entity with multivalued field with multiple properties and widget where only one of the properties is user-editable.
  2. Go to the entity edit form.
  3. Rearrange the field values in the background and save the entity e.g. from "0 => green rectangle, 1 => blue circle" make "0 => blue circle, 1 => green rectangle".
  4. On the entity edit form click "Add another item".
  5. Suddenly the field is exchanged and just by adding another item the user now sees something completely different and mixed up -> "0 => green circle, 1 => blue rectangle"

This happens because the form gets cached together with the entity only on the first ajax request.

Both problems occur only if the entity gets edited in the background between the form get request and the first ajax request, but will not occur if the entity gets edited in the background between the first and any following ajax requests.

Proposed resolution

We have to ensure the form gets rebuilt with the same entity the form was initially built.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
EntityΒ  β†’

Last updated 1 day ago

Created by

πŸ‡©πŸ‡ͺGermany hchonov πŸ‡ͺπŸ‡ΊπŸ‡©πŸ‡ͺπŸ‡§πŸ‡¬

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡·πŸ‡ΈSerbia holo96

    +1 issue for concurrent edits.

    My entity is neither translatable nor revisionable, but fields that are not exposed to form display at all are overwritten in case ajax (file uploads, multiple values fields etc.) is triggered. This can be huge issue that can result in data loss.

    I also think entity shouldn't be cached at all.

    Let's say products stock is managed by external service, it will be overwritten if someone is editing product even if stock is not exposed to form edit.

Production build 0.71.5 2024