Handle Missing $data['invalidations'][0] in Invalidation Check

Created on 29 October 2024, 9 months ago

Problem/Motivation

The problem is that if $data['invalidations'] does not have an element at index 0, the token replacement will not work, even if there are other elements in $data['invalidations'].

Steps to reproduce

  • Add an HTTP Bundled Purger -> then set the Type to Tag -> set the body to [invalidations:separated_comma]
  • Add an HTTP Bundled Purger again -> then set the Type to Path -> set the body to [invalidations:separated_comma]

Proposed resolution

We need to use reset($data['invalidations']) instead of $data['invalidations'][0] for the condition.

🐛 Bug report
Status

Active

Version

3.6

Component

Code

Created by

🇻🇳Vietnam hoanglv

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

Merge Requests

Comments & Activities

  • Issue created by @hoanglv
  • Assigned to divyansh.gupta
  • Pipeline finished with Success
    6 months ago
    Total: 1387s
    #390704
  • 🇮🇳India divyansh.gupta Jaipur

    Hello @hoanglv,
    Applied your patch and the changes looks good to me because this can solve the error as by using reset($data['invalidations']), the code will check if there is at least one element in $data['invalidations'], regardless of the key structure.
    Please review.

  • The issue occurs when $data['invalidations'] doesn't have an element at index 0, causing the token replacement to fail. By using reset($data['invalidations']) instead of $data['invalidations'][0], we ensure the first element (or default value if the array is empty) is accessed correctly. This change resolves the issue and improves the robustness of the functionality.

    So changes looks good to me so moving it to RTBC.

  • Issue was unassigned.
  • Status changed to Needs work about 2 months ago
  • 🇨🇦Canada nkind

    In trying this patch on our site with two servers it, for some reason, caused our purge cronjob to error with the following message:

    Drupal\purge\Plugin\Purge\Purger\Exception\BadPluginBehaviorException: Only NOT_SUPPORTED, PROCESSING, SUCCEEDED and FAILED are valid outbound states. in Drupal\purge\Plugin\Purge\Invalidation\InvalidationBase->setStateContext()

    Site is on 10.4.6 with all modules up to date.

Production build 0.71.5 2024