Problem/Motivation

Since Drupal 9.4.0 serializes and normalizers are expecting to implement CacheableSupportsMethodInterface::hasCacheableSupportsMethod(). By default, NormalizerBase implements it with a FALSE result, but ComplexDataNormalizer sets it to TRUE. That leads to caching result for ::supportsNormalization() module normalizers. But they shouldn't be cached because its ::supportsNormalization() is not type+format based. They are also check for route requirement, allowed fields and etc.

See #3252872: Use CacheableSupportsMethodInterface for performance improvement in normalizers

Steps to reproduce

  1. Update or install Drupal 9.4.0+
  2. Add something to cart
  3. Make a request to /cart?_format=json
  4. The Order Items will not contain a lot of data: price, quantity, total.

Proposed resolution

Implement ::hasCacheableSupportsMethod with FALSE result because we have checks not only based on type + format, but also field names and route requirements.

CommentFileSizeAuthor
#7 cart_error.png31.39 KBjasa
#2 commerce_cart_api-3292397-2.patch1.36 KBNiklan
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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Niklan created an issue. See original summary.

Niklan’s picture

Status: Active » Needs review
FileSize
1.36 KB
Niklan’s picture

Issue summary: View changes
Neograph734’s picture

Priority: Major » Critical
Status: Needs review » Reviewed & tested by the community

Confirming that this ensures that this module works again.

Upping to critical; in its current state this module is broken in D9.4.

simgui8’s picture

#2 works here too.

Thanks

jasa’s picture

I'm using Drupal 9.4.1 and the patch does not work in my case.

I am getting the same error each time I add a product to cart or I try to set Cart/Cart Flyout block:

Thanks in advance.

jasa’s picture

FileSize
31.39 KB
Neograph734’s picture

@jasa Did you clear the cache?

littlepixiez’s picture

#2 Works for me. Thank you so much for the quick fix!

rwanth’s picture

+1 RTBC. Thank you @Niklan for the patch.

attisan made their first commit to this issue’s fork.

  • attisan committed 9509667 on 8.x-1.x
    Issue #3292397: Implement CacheableSupportsMethodInterface::...
attisan’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the patch. Is now committed to dev.

attisan’s picture

Version: 8.x-1.x-dev » 8.x-1.6
Status: Fixed » Closed (fixed)