Overview

Reported by @balintbrews at #3503547-2: Display validation errors in dialogs that create sections.

Creating multiple code components in the UI with the same name results in a 500 response. This should've been caught in #3499931: HTTP API for code component config entities.

Proposed resolution

Match what JSON:API does:

    // Return a 409 Conflict response in accordance with the JSON:API spec. See
    // http://jsonapi.org/format/#crud-creating-responses-409.
    if ($this->entityExists($parsed_entity)) {
      throw new ConflictHttpException('Conflict: Entity already exists.');
    }

User interface changes

None — but this facilitates #3503547: Display validation errors in dialogs that create sections 👍

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

wim leers created an issue. See original summary.

wim leers’s picture

Issue tags: +undefined
wim leers’s picture

Issue tags: -undefined +Needs tests

LOL

wim leers’s picture

akhil babu made their first commit to this issue’s fork.

akhil babu’s picture

Status: Active » Needs review

Updated ApiConfigControllers::post() and added the tests. Please review

omkar-pd’s picture

Status: Needs review » Needs work

pipeline failed

wim leers’s picture

Thanks for pushing this forward! 🤩 🙏

This is on the right track, but there are a few things that make this brittle and incomplete. See my review on the MR 😊

akhil babu’s picture

Thanks @wimleers and @omkar, I have updated the PR to include both the js_componen and xb_asset_library entities. The same id error does not occur for pattern entities as Drupal\experience_builder\Entity\Pattern::generateId() updates the id if an entity with same id exists.

akhil babu’s picture

Status: Needs work » Needs review

Ready for review

wim leers’s picture

Assigned: Unassigned » wim leers
Issue tags: -Needs tests
wim leers’s picture

Assigned: wim leers » longwave

After @akhil babu's (great! 👏 — thanks! 😊🙏) work, 409 error responses started working, but they were using the same format as 500 responses (fatal server-side error), not the same as the much more similar 422 (validation error) responses.

That's bad, and @balintbrews already alluded to a similar problem in #3503547: Display validation errors in dialogs that create sections.

So let's do better. That was harder to explain than do, so I did it: https://git.drupalcode.org/project/experience_builder/-/merge_requests/6... (should pass, but GitLab CI is currently down)

But … that commit makes it painfully clear how inconsistent (and hence convoluted) the current handling is. That change makes the minimal change possible to make 409 responses similar to 422, but look at the crazy logic I had to write for it! 🤪

(This is nobody's fault: it grew organically. First we only had 500 errors, then we added an internal HTTP API that performed validation, so we added 422 responses for those. We decided to match JSON:API's error response structure for validation errors. Hence a mismatch was born.)

So … did that in https://git.drupalcode.org/project/experience_builder/-/merge_requests/6....

wim leers’s picture

Assigned: longwave » Unassigned
Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: +openapi

The sole test failure here is the same random failure we saw on 0.x overnight, as described in detail at #3499550-22: Support server-side massaging and validating of ComponentInputsForm values. The latest 0.x test run fails in a different random way.

There's no point explicitly awaiting @longwave's review here IMHO, this is fine as-is. 🤓

Also tightened /openapi.yml, both to have extra test assurances, and to let XB FE devs know what they should be able to expect.

wim leers’s picture

Status: Reviewed & tested by the community » Fixed

wim leers’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.