Cache issue for "url_link" enhancer

Created on 16 October 2024, 6 months ago

Problem/Motivation

I think there is a caching issue in the jsonapi_extras module when the “URL for link (link field only)” enhancer is enabled. Pathauto is assumed installed below :)

Steps to reproduce

  1. Add a link field to a node
  2. Create two nodes: “My first node” (so the pathauto is: /my-first-node) and “My second node” (so the pathauto is: /my-second-node)
  3. Populate the link field on /my-first-node with a link to /my-second-node
  4. Add the “URL for link (link field only)” enhancer to the link field (I don’t have “Absolute URLs” enabled but I don’t think it matters)
  5. See that the url in the jsonapi is pointing to “/my-second-node”
  6. Update /my-second-node with a new title so the pathauto is now “/my-second-node-with-new-title”
  7. See that the url in the jsonapi response still points to the “/my-second-node”.

If I drush cr manually, I see the correct (updated) url.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇩🇰Denmark blymemikkel Copenhagen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Pipeline finished with Canceled
    6 months ago
    Total: 296s
    #291931
  • Pipeline finished with Failed
    6 months ago
    Total: 213s
    #291934
  • Issue created by @blymemikkel
  • 🇩🇰Denmark blymemikkel Copenhagen
  • Pipeline finished with Success
    6 months ago
    #311755
  • 🇺🇸United States mglaman WI, USA

    The generated URL has the associated metadata but doesn't capture it.

            $url = Url::fromUri($data['uri'], ['language' => $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)]);
    
            // Use absolute urls if configured.
            $configuration = $this->getConfiguration();
            if ($configuration['absolute_url']) {
              $url->setAbsolute(TRUE);
            }
    
            $data['url'] = $url->toString();
          }
    

    From the field item normalizer:

        $context = new Context($context);
        $context->offsetSet('field_item_object', $object);
        $context->offsetSet(CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY, $cacheability);
        $processed = $enhancer->undoTransform(
          $normalized_output->getNormalization(),
          $context
        );
    

    The fix is something like

            $generatedUrl = $url->toString(TRUE);
            $context->offsetGet(CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY)->addCacheableDependency($url);
    
            $data['url'] = $generatedUrl->getGeneratedUrl();
    
  • 🇩🇰Denmark blymemikkel Copenhagen

    Thanks, Matt! It seems to work when I replicate my steps. Created an MR with your changes.

  • Pipeline finished with Failed
    6 months ago
    Total: 215s
    #311865
  • 🇺🇸United States mglaman WI, USA

    Great!

  • Pipeline finished with Failed
    6 months ago
    Total: 148s
    #314573
  • Pipeline finished with Skipped
    5 months ago
    #330582
  • Pipeline finished with Success
    4 months ago
    Total: 393s
    #348529
  • Pipeline finished with Success
    4 months ago
    Total: 224s
    #353486
  • Pipeline finished with Success
    4 months ago
    Total: 310s
    #353497
  • Pipeline finished with Success
    4 months ago
    Total: 328s
    #358968
  • Pipeline finished with Success
    4 months ago
    Total: 217s
    #361170
  • Pipeline finished with Skipped
    4 months ago
    #361173
  • First commit to issue fork.
  • Pipeline finished with Skipped
    4 months ago
    #361174
    • bbrala committed 14cd5d42 on 8.x-3.x authored by blyme
      Issue #3481163 by blyme, mglaman, bbrala: Cache issue for "url_link"...
  • 🇳🇱Netherlands bbrala Netherlands

    This is awesome, thank you so much. Looking good :)

  • Pipeline finished with Success
    4 months ago
    Total: 179s
    #361411
  • Pipeline finished with Success
    4 months ago
    Total: 178s
    #361414
  • Pipeline finished with Success
    4 months ago
    Total: 157s
    #363407
  • Pipeline finished with Success
    4 months ago
    Total: 281s
    #363762
  • Pipeline finished with Failed
    4 months ago
    Total: 272s
    #363838
  • Pipeline finished with Failed
    4 months ago
    Total: 360s
    #363917
  • Pipeline finished with Canceled
    4 months ago
    Total: 122s
    #363924
  • Pipeline finished with Success
    4 months ago
    Total: 224s
    #363925
  • Pipeline finished with Success
    4 months ago
    Total: 378s
    #363952
  • Pipeline finished with Success
    4 months ago
    Total: 216s
    #363965
  • Pipeline finished with Success
    4 months ago
    Total: 279s
    #363995
  • Pipeline finished with Success
    4 months ago
    Total: 141s
    #371790
  • Pipeline finished with Success
    4 months ago
    Total: 142s
    #371795
  • Pipeline finished with Success
    4 months ago
    Total: 269s
    #371798
  • Pipeline finished with Success
    4 months ago
    Total: 201s
    #372487
  • Pipeline finished with Success
    4 months ago
    Total: 146s
    #372547
  • Pipeline finished with Success
    4 months ago
    Total: 144s
    #372885
  • Status changed to Fixed 4 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Pipeline finished with Success
    2 months ago
    Total: 141s
    #405674
  • Pipeline finished with Success
    2 months ago
    Total: 179s
    #407165
  • Pipeline finished with Success
    2 months ago
    Total: 176s
    #407190
  • Pipeline finished with Success
    2 months ago
    Total: 178s
    #407194
  • Pipeline finished with Success
    2 months ago
    Total: 186s
    #407211
  • Pipeline finished with Success
    2 months ago
    Total: 175s
    #407213
  • Pipeline finished with Canceled
    2 months ago
    Total: 92s
    #407218
  • Pipeline finished with Success
    2 months ago
    Total: 192s
    #407219
  • Pipeline finished with Success
    2 months ago
    Total: 183s
    #407227
  • Pipeline finished with Success
    2 months ago
    #407232
  • Pipeline finished with Canceled
    2 months ago
    Total: 179s
    #407239
  • Pipeline finished with Success
    2 months ago
    Total: 182s
    #407240
  • Pipeline finished with Success
    2 months ago
    Total: 185s
    #407241
  • Pipeline finished with Success
    2 months ago
    Total: 144s
    #408219
  • Pipeline finished with Success
    2 months ago
    Total: 139s
    #408401
  • Pipeline finished with Success
    2 months ago
    Total: 150s
    #409037
  • Pipeline finished with Success
    2 months ago
    Total: 152s
    #409059
  • Pipeline finished with Success
    2 months ago
    Total: 182s
    #409088
  • Pipeline finished with Success
    2 months ago
    Total: 149s
    #415750
  • Pipeline finished with Success
    2 months ago
    Total: 147s
    #415822
  • Pipeline finished with Success
    2 months ago
    Total: 204s
    #415925
  • Pipeline finished with Success
    about 2 months ago
    Total: 151s
    #417881
  • Pipeline finished with Success
    about 2 months ago
    Total: 151s
    #417901
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 137s
    #420850
  • Pipeline finished with Success
    about 2 months ago
    Total: 142s
    #420855
  • Pipeline finished with Success
    about 2 months ago
    Total: 151s
    #420858
  • Pipeline finished with Success
    about 2 months ago
    Total: 151s
    #421133
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 270s
    #423242
  • Pipeline finished with Success
    about 2 months ago
    Total: 319s
    #423246
  • Pipeline finished with Success
    about 2 months ago
    Total: 150s
    #426535
  • Pipeline finished with Success
    about 2 months ago
    Total: 148s
    #426542
  • Pipeline finished with Success
    about 2 months ago
    Total: 151s
    #426547
  • Pipeline finished with Success
    about 2 months ago
    Total: 201s
    #430411
  • Pipeline finished with Success
    about 2 months ago
    Total: 155s
    #430591
  • Pipeline finished with Success
    about 2 months ago
    Total: 147s
    #430596
  • Pipeline finished with Success
    28 days ago
    Total: 198s
    #444675
  • Pipeline finished with Success
    5 days ago
    Total: 199s
    #463351
Production build 0.71.5 2024