Problem statement
The module adds event subscribers so that other modules can interact with data before sending them to akamai. Module also uses CacheTagFormatter to applying formatting to the cache tags before sending to akamai so that tags can work correctly with akamai.
Both these features are good but there is an inconsistency in AkamaiTagPurger::invalidate() method where it applies formatting first to the cache tags and then dispatch the events for changing them:
This causes following problems:
- Event subscribers can be expecting tag in the format of node:1 but instead they will get node_1 and their manipulation could fail.
- Event subscribers could add extra tags which will not be in proper format to work with akamai and can cause issues.
Proposed Resolution
Apply the formatting to cache tags after they have been altered with event subscribers.
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | fix_formatting-3160999-17.patch | 1.99 KB | smitghelani |
| #6 | fix_formatting-3160999-6.patch | 1.99 KB | guptahemant |
Issue fork akamai-3160999
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
guptahemant commentedComment #3
guptahemant commentedHere is a patch which fixes this issue.
Please review
Comment #5
Anonymous (not verified) commentedLooks good to me!
Maybe one very small remark
$formatted_tagsto$formatted_tags_to_clearComment #6
guptahemant commentedThanks for review @wouter.adem,
Attaching an updated patch containing fix for the failing test case and changing the variable name.
Please review
Comment #7
guptahemant commentedComment #8
Anonymous (not verified) commentedThe fix is ok.
The test has some typos, I think. Should
+ ['foo', 'bar', 123, '234', 456, true, 'on_purge_creation'],not be+ ['foo', 'bar', '123', '234', '456', true, 'on_purge_creation'],. Also, why wastrueadded and other tags left out?Comment #9
Anonymous (not verified) commentedComment #10
pobster commentedThis is a great catch, thank you for the patch! I'd really like a test for something being altered/ added though?
Comment #11
pobster commentedOkay, if you can't get round to making a test - I'll see if I can find time over the holidays.
Comment #12
guptahemant commentedHI @pobster
Until now i have not been able to find time to implement a test for the same, Also i am in the process of learning for writing tests,
In upcoming weeks will try to figure out how we can include an automated test functionality for this, Since we won't be directly able to use event subscribers(current test implementation) to test it completely.
Comment #13
WidgetsBurritos commentedComment #14
WidgetsBurritos commentedIn addition the feedback from @pobster above, I've noticed one other issue with this solution:
Since the formatted version is what is getting sent to Akamai, the
mb_strlen($tag)check needs to occur after the formatting, not before.In its present state
CacheTagFormatter::format()shouldn't modify the length of the cache tag at all, but we can't guarantee that will always be the case, especially if #3154613: Add cache-tag prefix is introduced.So we need to move the
mb_strlen($tag)check inside this loop instead:Comment #15
smitghelani commentedThis patch #6 is not working for the latest version 5.x, so created new patch with same code changes mentioned inside the #6. This is working for me.
Comment #16
smitghelani commentedComment #17
smitghelani commentedinside comment #15 i had missed 1 line to remove so adding new patch for the same.
Comment #18
pobster commentedI'm afraid it's still going to need a specific test though.
Plus, see this previous comment:
Comment #19
smustgrave commentedComment #21
smustgrave commentedDisclosure used AI to help right the unit test.
But during review found that typecasting to (string) means we don't need to update the one test
Comment #22
pobster commentedSure, LGTM
Comment #24
smustgrave commented