BreadcrumbBuilder::applies() mismatch with cacheability metadata

Created on 5 May 2016, over 8 years ago
Updated 3 June 2024, 6 months ago

Problem/Motivation

I am noticing the following problem with breadcrumbs, when I have my (sandbox) Configurable Help module installed, which has a custom breadcrumb class/service. This appeared recently -- it was not a problem before I recently did a git pull and updated my site to the latest 8.2.x, and berdir pointed me to #2699627: url.path cache context for breadcrumbs is unnecessarily granular β†’ as probably the cause? Not sure.

Steps to reproduce (you also need to have my sandbox Config Help module ( https://www.drupal.org/sandbox/jhodgdon/2369943 β†’ ) installed, branch 8.x-1.x-2697791, as well as the patch for #2697791: Add Plugin system for abstracted HTML-formatted text β†’ ... probably can make a smaller test case eventually. Anyway, for now:

a) Clear the cache

(b) Go to admin/config/system/cron (or any other admin page) - breadcrumb is OK

(c) Visit a Help Topic page (which uses my breadcrumb class) - breadcrumb is OK there

(d) Go back to the page in (b) and the breadcrumb is wrong -- it shows the breadcrumb from my Help Topic breadcrumb class/service instead.

If I repeat steps a-d, I can reproduce this problem over and over.

The breadcrumb class:
http://cgit.drupalcode.org/sandbox-jhodgdon-2369943/tree/src/HelpBreadcr...
The service definition:
http://cgit.drupalcode.org/sandbox-jhodgdon-2369943/tree/config_help.ser...

Proposed resolution

Revert or fix #2699627: url.path cache context for breadcrumbs is unnecessarily granular β†’

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated 34 minutes ago

Created by

πŸ‡ΊπŸ‡ΈUnited States jhodgdon Spokane, WA, USA

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    This surfaced as part of some extra hardening I'm trying to introduce into VariationCache: πŸ› VariationCache needs to be more defensive about cache context manipulation to avoid broken redirects Active

    Re #11:

    Does this mean we need to run through all breadcrumb builders?

    No, because they always run in the same order. So as long as we clear the cache when a new builder is introduced into the list, we're fine.

    Let's say you have 3 builders, the 1st applies() check varies by route, the 2nd by domain and the 3rd by user roles (for whatever reason). Then, as long as the first in the list applies, all we need to care about is the 'route' cache context. Only when the first one ever fails and we fall back to the second one, do add the url.site cache context. At this point, VariationCache will write a CacheRedirect at the current value for 'route', setting the 'url.site' cache contexts. Then, if both the 1st and 2nd applies() check fail, will another CacheRedirect be created to allow VC to store items from the 3rd builder.

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium
    The only other way that I see is that we introduce a new applies() method on a new interface that can return something like AccessResult. A binary result + cacheablity metadata.

    This was my first thought here - new interface, extend the old interface. We could also pass in an optional CacheableMetadata object into the applies method so the return doesn't need to change.

    Why note use the deprecation policy guideline on introducing a new argument to an existing signature? https://www.drupal.org/about/core/policies/core-change-policies/drupal-d... β†’

    I'll try that approach to allow a 2nd argument to be passed to applies().

  • Issue was unassigned.
  • Status changed to Needs review 6 months ago
  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium
  • Pipeline finished with Failed
    6 months ago
    Total: 131s
    #198688
  • Pipeline finished with Failed
    6 months ago
    Total: 132s
    #198687
  • Pipeline finished with Failed
    6 months ago
    #198690
  • Status changed to Needs work 6 months ago
  • The Needs Review Queue Bot β†’ tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request β†’ . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

  • Pipeline finished with Failed
    6 months ago
    Total: 648s
    #198708
  • Status changed to Needs review 6 months ago
  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Should go green now. From the other issue:

    This caused StandardPerformanceTest to fail as there are now 2 more cache gets, which makes sense because we added a cache context.

  • Pipeline finished with Failed
    6 months ago
    Total: 583s
    #198775
  • Pipeline finished with Failed
    6 months ago
    Total: 548s
    #198793
  • Pipeline finished with Failed
    6 months ago
    Total: 516s
    #198832
  • Pipeline finished with Success
    6 months ago
    Total: 512s
    #198843
  • Status changed to Needs work 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    The issue summary mentions "Revert or fix #2699627: url.path cache context for breadcrumbs is unnecessarily granular β†’ " can I ask which one it is? Maybe this can be flushed out more. Don't think this is an API or model change so put those as N/A

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    The MR is the correct approach, it's just that the issue summary needs severe updating.
    The new approach is #10, #36 and #37

    In essence: Allow the applies() method to set cacheability. Because the breadcrumb builders run in the same order every time and because only one can build the actual breadcrumb, we don't need to care about ALL builder's cacheable metadata, just the data up until the builder that actually applies.

    I'll try to update the IS tomorrow.

  • πŸ‡³πŸ‡±Netherlands mike.vindicate

    Attached a patch that can be used for Drupal 10.2. Thanks for fixing the issue.

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Please don't convert MRs into patches as it creates a lot of unnecessary noise. Especially when the MR is still up for review and might change.

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium
  • Status changed to Needs review 6 months ago
  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    @smustgrave Updated the IS to reflect the actual bug and how it should be fixed. The initial IS was just one case of running into it, but πŸ› VariationCache needs to be more defensive about cache context manipulation to avoid broken redirects Active exposes the problem in more detail as it also causes incorrect cache redirects to be written.

  • Status changed to Needs work 6 months ago
  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    Maybe because I'm tired, but I had a really hard time reading the doc block to try and understand what it was trying to say. Grammatically strange sentences and missing capital letters as well.

    Code wise not much to add to the review. Looks clean and the other comments are easy to read.

  • Status changed to Needs review 6 months ago
  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Hopefully this is a bit easier on the eyes.

  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    Already better πŸ™‚

    The cacheable metadata to add to if your check varies by or depends on something

    Can't the "to" be removed? Or specify to what we're adding metadata?

    Anything you specified here does not have to be repeated in the build() method as it will be merged in automatically.

    Anything you have? ... merged automatically?

    I'm no native english speaker, but with above changes I suggested it would read easier to me.

  • Pipeline finished with Success
    6 months ago
    Total: 646s
    #202034
  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Can't the "to" be removed?

    That would make it broken English. You have the infinite "to add" and then "to" as you're adding to something (the CacheableMetadata).

    Or specify to what we're adding metadata?

    This documentation is for the $cacheable_metadata parameter, so I think it should be clear that that's the thing you're adding to?

    Anything you specified here does not have to be repeated in the build() method as it will be merged in automatically.

    You can use "Anything you specify here" or "Anything you specified here", depending on whether you want it to read like a forward-looking suggestion or vice versa. I wouldn't use "have", though. If you want we can change it to the present tense.

    As for "merged in", it's because you merge whatever was specified into the final result. Because that sentence has no mention of "the final result", the "to" part of "into" is dropped. Example: John was about to walk into the river, as he walked in, he felt something sharp beneath his feet.

  • Status changed to RTBC 6 months ago
  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    Nah, it’s fine then πŸ˜‡ again, not a native speaker. πŸ˜‰

  • πŸ‡ΊπŸ‡ΈUnited States neclimdul Houston, TX

    I think I understand the reason of the change and it makes sense. Previously you'd have to return true from applies if you _might_ apply and then builder would have to do the actual check and apply the cache-ability. Yeah, that's a pretty big gotcha when building these builders.

    Looking at the merge, there's a lot of duplicate adding of the route to the cache-ability. I guess maybe this is a dumb question and probably well understood in the building of BreadcrumbManager but isn't varying by route kinda a baseline implied functionality for breadcrumb builders? That's why we pass the route_manager in right? Should the manager just include that by default and this change would only be used for more exotic cases?

    If it helps the discussion, and example where it doesn't cache by route in core is PathBasedBreadcrumbBuilder. I found that's broken on our site and actually decorate the core version with one that adds the route to the cache-ability of the path breadcrumb builder.

  • Status changed to Needs review 6 months ago
  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    No worries :) I'm not a native speaker either but I tend to want to get the grammar right, so I tend to look these things up when in doubt. You did make me think, though, and I believe the simple present is preferred here, as the implementation is arguably still to be written at the time of reading the documentation.

    Will change that little detail and leave at RTBC.

  • Status changed to RTBC 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States neclimdul Houston, TX

    left rtbc because this isn't a change this merge makes just something it highlights so could be a follow up.

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Should the manager just include that by default and this change would only be used for more exotic cases?

    It could, but just like you I'd argue that that is out of scope. For now I would focus on fixing the bugs caused by not correctly setting any cacheable metadata when the applies() check returns FALSE.

  • Pipeline finished with Success
    6 months ago
    Total: 507s
    #202121
  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    RE #54 now it reads better to my mind πŸ˜…

  • Status changed to Needs work 5 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    I have some BC concerns added to the MR.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    This issue also requires a CR as implementations in contrib and custom code will need to change.

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Will try to fix these minor issues tomorrow. In the meantime, I answered the question regarding cache operation counts.

  • Pipeline finished with Canceled
    5 months ago
    Total: 175s
    #216721
  • Pipeline finished with Success
    5 months ago
    Total: 474s
    #216726
  • Status changed to Needs review 5 months ago
  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Only needs a follow-up to change the signatures in D12.

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium
  • Pipeline finished with Success
    5 months ago
    Total: 541s
    #216731
  • Pipeline finished with Canceled
    5 months ago
    Total: 31s
    #216743
  • Pipeline finished with Canceled
    5 months ago
    Total: 145s
    #216744
  • Pipeline finished with Canceled
    5 months ago
    Total: 15s
    #216746
  • Pipeline finished with Success
    5 months ago
    Total: 474s
    #216747
  • Status changed to RTBC 5 months ago
  • πŸ‡­πŸ‡ΊHungary mxr576 Hungary

    Reviewed the CR and both the MR. I could only nitpicking on consistency regarding whether we have , see [link]. or . See [link], but since PHPCS is happy, I can be happy with the current comments too, they are still readable and understandable.

  • Status changed to Fixed 5 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Committed a75df83 and pushed to 11.x. Thanks!

    • alexpott β†’ committed bb5bc5db on 11.0.x
      Issue #2719721 by kristiaanvandeneynde, jhodgdon, BramDriesen, pameeela...
    • alexpott β†’ committed 7f752fe0 on 10.4.x
      Issue #2719721 by kristiaanvandeneynde, jhodgdon, BramDriesen, pameeela...
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Discussed with @catch and we agreed to backport this to 11.0.x and 10.4.x.

    • alexpott β†’ committed a75df83c on 11.x
      Issue #2719721 by kristiaanvandeneynde, jhodgdon, BramDriesen, pameeela...
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • πŸ‡¬πŸ‡§United Kingdom james.williams

    Thanks for this improvement! I have though found a bug for a follow-up: the cacheability is ignored if no breadcrumb builders apply, which can cause breadcrumbs to disappear across a whole site. Reported as πŸ› BreadcrumbManager ignores cacheability when no builders apply Active .

Production build 0.71.5 2024