I made a block using the 'cookies' context tag, which means "vary by all cookies". I got the error in the title. I found out that it's because CookiesCacheContext::getContext() does not respect it's interface definition. It must always return a string.

I don't know if the automatic array to string conversion might cause problems with the caching system, I just tried to get rid of the notice message.

Comments

GaëlG created an issue. See original summary.

dawehner’s picture

Interesting, do you mind writing a test for that?

berdir’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Yes, this is clearly a bug and a test would be good.

That said, are you sure your block really needs to vary by *all* cookies? If you have any sort of tracking or ads on your site then you will end up with unique cache contexts for every visitor.

gaëlg’s picture

@Berdir: actually I already changed my code to vary by one cookie only, as the bug made me think a bit more. I guess it's a very rare need to vary by all cookies. Thank you anyway. About tests, I'm not used to writing tests and I have not much time to work on this.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

vijaycs85’s picture

Version: 9.3.x-dev » 9.4.x-dev
StatusFileSize
new1.58 KB
new2.52 KB

Here is the test and combined patch...

vijaycs85’s picture

Status: Needs work » Needs review
vijaycs85’s picture

StatusFileSize
new1.53 KB
new2.47 KB

The last submitted patch, 15: 2873732-15-test-only.patch, failed testing. View results

longwave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Fix and test looks OK to me.

alexpott’s picture

Version: 9.4.x-dev » 9.3.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed fd664f7 and pushed to 9.4.x. Thanks!

Discussing with other committers about when to backport this to 9.3.x

  • alexpott committed fd664f7 on 9.4.x
    Issue #2873732 by vijaycs85, GaëlG: Array to string conversion in...

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

alexpott’s picture

Version: 9.4.x-dev » 9.3.x-dev
Status: Patch (to be ported) » Fixed

Cherry picked this to 9.3.x. It's not disruptive and fixes a bug.

  • alexpott committed 163191c on 9.3.x
    Issue #2873732 by vijaycs85, GaëlG: Array to string conversion in...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.