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
- Update or install Drupal 9.4.0+
- Add something to cart
- Make a request to /cart?_format=json
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | cart_error.png | 31.39 KB | jasa |
| #2 | commerce_cart_api-3292397-2.patch | 1.36 KB | niklan |
Issue fork commerce_cart_api-3292397
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
Comment #2
niklanComment #3
niklanComment #4
neograph734Confirming that this ensures that this module works again.
Upping to critical; in its current state this module is broken in D9.4.
Comment #5
simgui8 commented#2 works here too.
Thanks
Comment #6
jasa commentedI'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.
Comment #7
jasa commentedComment #8
neograph734@jasa Did you clear the cache?
Comment #9
littlepixiez commented#2 Works for me. Thank you so much for the quick fix!
Comment #10
rwanth+1 RTBC. Thank you @Niklan for the patch.
Comment #14
attisanThanks for the patch. Is now committed to dev.
Comment #15
attisan