Problem/Motivation

From See #2800873-124: Add XML GET REST test coverage, work around XML encoder quirks:

But for XML [serialization of the ImageStyle config entity], this is the response you get:

Fstring(2801) "The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">DOMException</em>: Invalid Character Error in <em class="placeholder">DOMDocument-&gt;createElement()</em> (line <em class="placeholder">452</em> of <em class="placeholder">vendor/symfony/serializer/Encoder/XmlEncoder.php</em>). <pre class="backtrace">Symfony\Component\Serializer\Encoder\XmlEncoder-&gt;appendNode(Object, Array, &#039;574d9c11-33ec-4fa7-9a6b-6783600c9cfa&#039;) (Line: 408)
Symfony\Component\Serializer\Encoder\XmlEncoder-&gt;buildXml(Object, Array) (Line: 490)
Symfony\Component\Serializer\Encoder\XmlEncoder-&gt;selectNodeType(Object, Array) (Line: 456)
Symfony\Component\Serializer\Encoder\XmlEncoder-&gt;appendNode(Object, Array, &#039;effects&#039;) (Line: 408)
Symfony\Component\Serializer\Encoder\XmlEncoder-&gt;buildXml(Object, Array, &#039;response&#039;) (Line: 65)
Symfony\Component\Serializer\Encoder\XmlEncoder-&gt;encode(Array, &#039;xml&#039;, Array) (Line: 60)
Drupal\serialization\Encoder\XmlEncoder-&gt;encode(Array, &#039;xml&#039;, Array) (Line: 38)
Symfony\Component\Serializer\Encoder\ChainEncoder-&gt;encode(Array, &#039;xml&#039;, Array) (Line: 233)
Symfony\Component\Serializer\Serializer-&gt;encode(Array, &#039;xml&#039;, Array) (Line: 118)
Symfony\Component\Serializer\Serializer-&gt;serialize(Array, &#039;xml&#039;) (Line: 156)
Drupal\rest\EventSubscriber\ResourceResponseSubscriber-&gt;Drupal\rest\EventSubscriber\{closure}() (Line: 574)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 157)
Drupal\rest\EventSubscriber\ResourceResponseSubscriber-&gt;renderResponseBody(Object, Object, Object, &#039;xml&#039;) (Line: 74)
Drupal\rest\EventSubscriber\ResourceResponseSubscriber-&gt;onResponse(Object, &#039;kernel.response&#039;, Object) (Line: 108)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher-&gt;dispatch(&#039;kernel.response&#039;, Object) (Line: 193)
Symfony\Component\HttpKernel\HttpKernel-&gt;filterResponse(Object, Object, 1) (Line: 175)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)
</pre>"

The root cause:

        $this->effectUuid => [
          'uuid' => $this->effectUuid,
          'id' => 'image_scale_and_crop',
          'weight' => 0,
          'data' => [
            'width' => 120,
            'height' => 121,
          ],
        ],

i.e. a UUID is being used as a key for an array, which means that the XML encoder will try to map this to an XML tag (element). And dashes aren't allowed in XML tag/element names, hence this exception.

I don't see a way to work around this. But it also shouldn't hold up everything else. So created a new issue for that: #2905655: XML encoder does not support UUIDs as keys: makes ImageStyle config entity XML serialization crash.

Therefore for now including stub test coverage.

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

None.

API changes

TBD

Data model changes

TBD

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers created an issue. See original summary.

Wim Leers’s picture

Title: [PP-1] XML encoder does not support UUIDs as keys » XML encoder does not support UUIDs as keys
Status: Postponed » Active
Wim Leers’s picture

Title: XML encoder does not support UUIDs as keys » XML encoder does not support UUIDs as keys: makes ImageStyle config entity XML serialization nonsensical
Status: Active » Needs review
FileSize
2.49 KB

This is what we need to achieve.

Wim Leers’s picture

Issue summary: View changes

Updated IS by lifting the contents of the comment where this was first discovered.

Wim Leers’s picture

Title: XML encoder does not support UUIDs as keys: makes ImageStyle config entity XML serialization nonsensical » XML encoder does not support UUIDs as keys: makes ImageStyle config entity XML serialization crash
Component: serialization.module » image.module

I see only two possible ways to solve this:

  1. Changing the data structure of ImageStyle config entities. This is a data model change. Theoretically a BC break, but an automated update path could be provided. Plus, it's possible there are contrib/custom config entities that have a similar data structure. It should not be necessary for the data structure to disallow UUIDs as keys just because XML can't encode it.
  2. Customize our XML encoder, to make it detect UUIDs, and upon encountering one, automatically transform af73797f-15d3-4140-b684-d6bf1c7897fe to <uuid value="af73797f-15d3-4140-b684-d6bf1c7897fe"> or something like that. But our XML normalizer is blissfully unaware of attributes, so not sure how yet. Also, the UUID is repeated in the map itself, so it'd end up looking silly.

So perhaps it is best to go with option 1. Because

$this->effectUuid => [
  'uuid' => $this->effectUuid,
…
]

is pretty silly.

Moving this to the image.module component to get feedback.

Status: Needs review » Needs work

The last submitted patch, 3: 2905655-3.patch, failed testing. View results

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.