- Issue created by @idiaz.roncero
- πΊπΈUnited States jldust
The error most likely comes from the empty object being encoded as an empty array during validation. We could look into the way its being read, possibly set a boolean if a component has no props or validate if the props key is present.
- π΅π±Poland wotnak
Related to https://www.drupal.org/project/drupal/issues/3365480 π [SDC] Improve error handling during prop validation errors Fixed where similar problem was fixed for passed props validation.
Same fix of adding `Constraint::CHECK_MODE_TYPE_CAST` as a third argument to `$this->validator->validate()` applied at https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/sdc/s... should help. It will validate schema using loose type checking https://github.com/justinrainbow/json-schema/blob/master/src/JsonSchema/... that will treat empty and associative php arrays as valid objects. - last update
about 1 year ago 30,473 pass, 9 fail - @e0ipso opened merge request.
- Status changed to Needs review
about 1 year ago 10:36pm 31 October 2023 - e0ipso Can Picafort
I don't remember having to create the MR manually in GitLab. Maybe it's a hiccup in the GitLab <-> Drupal integration. In any case, here's the MR.
- Status changed to Needs work
about 1 year ago 7:25pm 1 November 2023 - πΊπΈUnited States jldust
I tried applying the patch on D10.1.6 and ran into conflict with 2 files.
It looks like it mostly applied the ComponentRenderTest.php patch so I'm not sure why that is throwing an error.- error: patch failed: core/modules/sdc/tests/src/Kernel/ComponentRenderTest.php:43
- error: core/modules/sdc/tests/src/Kernel/ComponentRenderTest.php: patch does not apply
When trying to apply against 11-dev it wasn't able to apply at all.
- Status changed to Needs review
about 1 year ago 8:43pm 1 November 2023 - First commit to issue fork.
- Status changed to RTBC
about 1 year ago 3:24pm 7 November 2023 - πΊπΈUnited States smustgrave
Rebased so I could run test only feature but it didn't run correctly and removed the test modules https://git.drupalcode.org/issue/drupal-3385283/-/jobs/288144
So ran locally and I was unable to get the tests to run without the fix.
hiding the patch file as fix is in MR.
Check for empty properties seems good and don't see any issue.
- π¬π§United Kingdom alexpott πͺπΊπ
Committed and pushed 99040d47906 to 11.x and a4785d91b50 to 10.2.x. Thanks!
Backported to 10.2.x as a major bug fix.
- Status changed to Fixed
about 1 year ago 10:00am 15 November 2023 -
alexpott β
committed 99040d47 on 11.x
Issue #3385283 by e0ipso, smustgrave, idiaz.roncero, jldust, wotnak:...
-
alexpott β
committed 99040d47 on 11.x
-
alexpott β
committed a4785d91 on 10.2.x
Issue #3385283 by e0ipso, smustgrave, idiaz.roncero, jldust, wotnak:...
-
alexpott β
committed a4785d91 on 10.2.x
- πΊπΈUnited States fathershawn New York
I'm intentionally commenting on this fixed issue because I think the committed code contains a logic error. The committed change is
// If there are no props, force casting to object instead of array. if (($schema['properties'] ?? NULL) === []) { $schema['properties'] = new \stdClass();
However
NULL === []
is always false, so if the properties key does not exist, it is not added via this code and an error is still thrown when in::nullifyClassPropsSchema()
. I think the correct logic is:// If there are no props, force casting to object instead of array. if (($schema['properties'] ?? []) === []) { $schema['properties'] = new \stdClass();
See https://3v4l.org/u5CM5#v8.1.19 for a simple demo.
- π¬π§United Kingdom alexpott πͺπΊπ
@FatherShawn this converts [] to an object when $schema['properties'] has been set to an empty array. As per #2...
The error most likely comes from the empty object being encoded as an empty array during validation. We could look into the way its being read, possibly set a boolean if a component has no props or validate if the props key is present.
- πΊπΈUnited States fathershawn New York
Thanks @alexpott. I see that the logic error in the code does not affect the stated bug. We were getting some cases where there this same method throws an error due to the lack of a
'properties'
key and at first glance it looked like this fix was intended to address both cases. I'll dig into our case further with xdebug and open another issue if needed. - e0ipso Can Picafort
@FatherShawn you are correct, but there is a gotcha. The
'properties'
key still needs to exist, but now you can set it to an empty object{}
(which translates to[]
in PHP land). The reason for that is to be explicit. If your components doesn't have props you have to say my component does not have props, we are not accepting silence about your props (as we are not inferring that that means that your component doesn't have them).Does that make sense? I think favoring explicitness is positive here, but I wonder how you feel about that.
Automatically closed - issue fixed for 2 weeks with no activity.
- Status changed to Fixed
6 months ago 5:32pm 18 June 2024