After installing rc3, if I try to visit the members or nodes tabs (e.g. group/1/members and group/1/nodes), I see "The website encountered an unexpected error. Please try again later." (I had to tag this issue as rc2, because there is no option for rc3 yet in the Version menu of the bug tracker.)

In my error log, I see...

Uncaught PHP Exception Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException: "You have requested a non-existent service "cache_context.group_membership.roles.permissions". Did you mean one of these: "cache_context.group_membership.audience", "cache_context.group_membership.roles"?" at /var/www/projects/public_html/core/lib/Drupal/Component/DependencyInjection/Container.php line 153

I see in your release notes (https://www.drupal.org/project/group/releases/8.x-1.0-rc3) you say "Cache contexts have received an overhaul, please check your code for deprecated ones. For security reasons, group_membership.roles.permissions has been removed!" However, when I grep through my entire web directory I see no instances of group_membership.roles.permissions except in the update routines in the install files for the group module and gnode. This is a sandbox site with no custom theming and only one custom module installed.

My Drupal version is 8.7.3.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

arnoldbird created an issue. See original summary.

arnoldbird’s picture

Priority: Normal » Major
arnoldbird’s picture

Priority: Major » Normal

I have found that if I save these two views, the problem goes away...

admin/structure/views/view/group_members
admin/structure/views/view/group_nodes

It's not necessary to make any change to these views. Just visit the edit screen and click save.

I'm changing the issue status to normal since there is an easy workaround.

willabby’s picture

I had same error message, your quick fix worked as well for me, thank you!

prerit_mohan_bhatnagar’s picture

Anyone knows the cause of this? One similar occurrence is here when the group data is exposed via API https://www.drupal.org/project/group/issues/2906082#comment-12818713

I also saved my custom view again as a workaround fix.

Thanks

SocialNicheGuru’s picture

this is a change record which explains: https://www.drupal.org/node/3061215

Anne-Pierre’s picture

Same here, #3 worked for me.

kristiaanvandeneynde’s picture

Did any of you run the database update like you're supposed to after every module upgrade? :)

rgpublic’s picture

@kristiaanvandeneynde: I just upgraded, as we are upgrading with a special script which ALWAYS does a "drush updb" at the end I know for sure that database updates have been executed. Nevertheless I got the error. #3 worked for me, though. So only a little shock moment after the upgrade ;-)

kristiaanvandeneynde’s picture

Hmm, if someone has exact steps to reproduce after running updb/cr, please let me know.

arnoldbird’s picture

@kristiaanvandeneynde Yes, I ran update.php, and cleared the performance cache, etc. I also tried truncating all db tables starting with cache*. Nothing worked except saving the Members and Nodes views.

kristiaanvandeneynde’s picture

That's odd because the update hooks are supposed to remove the use of "cache_context.group_membership.roles.permissions" from those views :/

SocialNicheGuru’s picture

I just did a search on my system. There are other modules that call group_membership.roles.permissionss.

grep group_membership.roles.permissions -d recurse modules
grep group_membership.roles.permissions -d recurse profiles

There were several modules that I had installed that did not have the upgrade. For now I had to downgrade to rc2 and I added issues to those modules that this change in group rc3 has occurred.

I am also on Drupal 8.7.3

https://www.drupal.org/node/3061215

arnoldbird’s picture

@SocialNicheGuru

"I just did a search on my system. There are other modules that call group_membership.roles.permissionss"

For what it's worth, this is not the case in my install. As noted in the issue description, I grep'd through my entire web directory and the only instances of that string are found in the .install files in the group module and gnode module.

kristiaanvandeneynde’s picture

Re #13: That context was removed because it was deemed insecure. I'd urge the maintainers of those modules to upgrade quickly :)

arnoldbird’s picture

FileSize
40.63 KB

"if someone has exact steps to reproduce after running updb/cr, please let me know."

I did a fresh Drupal install just now with...

composer create-project drupal-composer/drupal-project:8.x-dev projects2 --no-interaction

And I downloaded group module, rc1:

composer require drupal/group:1.0-rc1

I enabled the group module and created one group type and one group. I saw "admin" was listed twice as a member of the group -- please see attached screenshot. I deleted one of those relationships so admin only appears once. I then created one new user and made the user a member of the group.

I then upgraded to rc3:

composer require drupal/group:1.0-rc3

I then visited update.php. I saw there were four updates to perform, two for gnode (8005 and 8006) and two for group (8015 and grant_access_overview_permission). I ran the updates. I then visited group/1/members and I see "The website encountered an unexpected error. Please try again later." In my log I have...

[Fri Jun 14 12:09:24.279289 2019] [:error] [pid 11248] [client 127.0.0.1:47116] Uncaught PHP Exception Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException: "You have requested a non-existent service "cache_context.group_membership.roles.permissions". Did you mean one of these: "cache_context.group_membership.audience", "cache_context.group_membership.roles"?" at /var/www/projects2/web/core/lib/Drupal/Component/DependencyInjection/Container.php line 153, referer: http://projects2.ryan.com/group/1

I then cleared the performance cache at admin/config/development/performance but I get the same error when I visit group/1/members. I then tried clearing the cache with drush cr, but I get the same error when I visit group/1/members.

I then visited the Members view and saved it. Error goes away, but I still have the error in the Nodes tab. I then visit the group nodes view and save that, and then the error goes away in the Nodes tab.

C.E.A’s picture

Same here, #3 worked for me.

kristiaanvandeneynde’s picture

Okay, must be something wrong with the update function then. Thanks for the detailed report!

wizardfish’s picture

Ran into the same thing today, seems to have started after our last update 4 days ago. Caches were cleared and update.php was run after the updates.

Full error message:
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "cache_context.group_membership.roles.permissions". Did you mean one of these: "cache_context.group_membership.audience", "cache_context.group_membership.roles"? in Drupal\Component\DependencyInjection\Container->get() (line 153 of ./web/core/lib/Drupal/Component/DependencyInjection/Container.php).

I was able to access group/1/members and group/1/nodes, so the fix in #3 didn't work for me. The problem was reaching the main group pages (view tab), "website encountered an unexpected error...". Using the same technique in #3 on a couple of our custom views did the trick.

laboratory.mike’s picture

In my case, I did a search of the database for 'group_membership.roles.permissions' , and found a custom view referencing it. I turned caching off, saved the view, then re-enabled caching, and its working now.

I am maintaining one of the modules referenced in #13, and I'm working on an update function to cover the affected views. If you would like, I can forward it to y'all either for a general update, or as instructions for other maintainers of Group-integrated modules.

Anne-Pierre’s picture

Hello kristiaanvandeneynde,
Yes I did run the database update after the install of RC3.
Thanks for the module. It is very useful.

mmilaprat’s picture

I did an export using the "configuration syncronization", and I search in the *.yml files the string "group_membership.roles.permissions" to find the list of views that I must save again

idebr’s picture

Status: Active » Needs review
FileSize
1.75 KB

Attached patch adds a post_update hook to remove the 'group_membership.roles.permissions' cache context from all existing views.

// Remove the deleted cache context and add the updated metadata.
if ($key = array_search('group_membership.roles.permissions', $cache_metadata['contexts'])) {
  unset($cache_metadata['tags'][$key]);
}

The earlier updates failed since array_search returned 0 could return 0 and the $key was unset from the wrong array key 'tags' instead of 'contexts'.

Lendude’s picture

Version: 8.x-1.0-rc2 » 8.x-1.x-dev
Priority: Normal » Critical
Status: Needs review » Reviewed & tested by the community

Bumping to critical because this leads to a fatal error after doing the update.

Code looks good and verified that it clears up the fail and the view is updated correctly.

kristiaanvandeneynde’s picture

Oh crap, I usually make a habit out of if (array_search() !== FALSE), don't know why I missed that here. Thanks for the patch! Will try to review and commit early next week. I'm not pushing a new release on a Friday at 4PM.

xurizaemon’s picture

xurizaemon’s picture

kristiaanvandeneynde’s picture

@idebr why the post update hook, though? Changing views is perfectly safe and probably much faster from a regular update hook.

Lendude’s picture

post_update FTW, always post_update unless there is a reason you can't use it (Schema updates et al.), safer because the API is fully stable and zero chance of merging two patches that both declare the same hook update number, so less error prone and less re-rolling needed.

Just my 2 cents obviously :)

kristiaanvandeneynde’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
3.13 KB

Hmm, I'm more of a purist. Config changes go into update hooks, content changes in post-update. Merge conflicts happen, so I'm not too bothered by them, but I can see the upside of always using post-update hooks. Then again, I can also see some downsides because of how it works.

Either way, how about this? It fixes the update hooks for people who haven't upgraded yet and introduces a new one for people who have and are experiencing problems.

Lendude’s picture

Not a fan of rewriting update hooks personally because it is sort of rewriting history (some people will have run a different version of that hook then is actually in code, which could lead to major confusion should something unforeseen happen), I would just leave the old hook as it is, but maybe I am a purist in that :)

kristiaanvandeneynde’s picture

The problem is that update hooks are run in order. So if you have a broken one and don't fix it, then someone upgrading from RC2 -> RC4 will still run the wrong code. By fixing/emptying the old one, you make sure people won't run bad update code.

Anyways: Let's see what people think of this patch. Will try to run it myself sometime tomorrow or Wednesday.

xurizaemon’s picture

We tested this patch yesterday and found it did not resolve issues on a site which was already showing the error 'You have requested a non-existent service "cache_context.group_membership.roles.permissions".'

I did test additionally edit => save on the affected views, but wasn't able to get the site back. Due to time constraints I wasn't able to debug further and rolled back to rc2 instead.

Since I don't have info to add yet, I don't want to move this back to "Needs work", but I wanted to give at least some signal here that it didn't work as hoped when I tried it. Plan to test further and give more informed feedback then.

idebr’s picture

#33 The cache context might be used in other places than Views. Can you provide a backtrace where the cache context is called to see if this something we can fix in Group?

xurizaemon’s picture

OK, second time around I was more careful. Seems to have worked, testing the project's full migration process against rc3 now. Guessing last time I didn't update enough of the group-referencing views is all.

I edit-saved about a dozen views that referenced groups (those that matched entity_type: group or entity_type: group_content) on the site. However when I ran a config:export to sync, I saw that almost all views on the site (48 of 54 views) had the same change applied, adding route.group and user.group_permissions to the view contexts for a variety of views through the site, the majority of which do not reference entities group or group_content.

Doesn't seem like a major problem, might be expected behaviour, sharing in case it's of interest.

Thanks!

kristiaanvandeneynde’s picture

Status: Needs review » Needs work

Good catch, that's a bug. The old update code targeted some views specifically, the new one doesn't so it can't assume it needs to add the new context. Only when a view had the old context, should we add the new one. Good catch!

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
FileSize
1.65 KB
3.29 KB

This only changes views that had the old context.

Status: Needs review » Needs work

The last submitted patch, 37: group-3061321-37.patch, failed testing. View results

phjou’s picture

The patch in #30 fixed the error for me. Thanks!

xurizaemon’s picture

@phjou current patch is #37

Unsure about the test bot failures, "mkdir failed" looks like infra things not test things, retesting.

kristiaanvandeneynde’s picture

Status: Needs work » Needs review
Lendude’s picture

So the only remaining possible problem I see here is #34, usage of the removed cache context outside Views.

Possible solutions:

  • Revert the deletion and properly @deprecated the old context, remove it later (core style)
  • Update the update hook to remove it from all config (don't see how that would work, but didn't dig into it)
  • Accept that this maybe breaks some sites and move forward

Reading the original CR for this https://www.drupal.org/node/3061215 it seems that option three was the chosen solution for this, so in that light, #34 should not be blocking this.

DeanLiddle’s picture

Can confirm that #3 fixes the issue for me also.

SocialNicheGuru’s picture

I have to remain on rc2.
I had to clear the cache
and #3 did work.

tanasi’s picture

The patch in #30 fixed the error for me as well. Thanks!

ralfsutorius’s picture

Can confirm that #3 fixes the issue for me, too. Is it necessary to install group-3061321-37.patch or should I wait for RC4?

mc.edwards’s picture

#3 has not worked for me and in fact threw up additional incomprehensible messages which were replicate when I tried again after clearing the cache. The following error persists
AssertionError: assert($this->assertValidTokens($context_tokens)) in assert() (line 103 of core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php).
I'm pretty new to this Drupal business and it's impossible for me to understand from this thread what to do. I'm reverting to RC2 and will wait for RC4 - will it be fixed then? Should I be applying the patch in #37?

rjg’s picture

The patch in #37 works for me

kristiaanvandeneynde’s picture

@Lendude in #43 we chose to do this the hard way because it was a security issue waiting to happen. Sometimes, tough decisions need to be made :/

Pushing ahead with the patch from #37.

kristiaanvandeneynde’s picture

Status: Needs review » Fixed
Lendude’s picture

@kristiaanvandeneynde++ for making the tough decisions. Thanks for committing this.

catch’s picture

The fix committed here doesn't take into account exported/default config in other modules. It would be worth moving to config presave so that it catches those too - then the update just has to load and resave the config without doing any specific manipulation. There are some similar examples in views already.

catch’s picture

Status: Fixed » Active

Re-opening for discussion. Here's what Views does: https://api.drupal.org/api/drupal/core%21modules%21views%21views.module/...

catch’s picture

Status: Active » Needs review
FileSize
3.51 KB

Here's a patch implementing #53.

plach’s picture

Status: Needs review » Reviewed & tested by the community

Makes sense to me: this will take core also of views that have not been installed yet but are still relying on the old cache context.

A minor nit, if we happen to reroll the patch:

+++ b/group.post_update.php
@@ -45,3 +46,15 @@ function group_post_update_grant_access_overview_permission() {
+  \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'view', function($view) {

Missing space after function keyword.

kristiaanvandeneynde’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
6.69 KB

I updated the patch to also clean out the other update functions, fixed spacing issues and a bug because $update = FALSE; was part of the loop instead of outside of it. Please review. Messed up the interdiff locally but patch is small enough as is.

idebr’s picture

Some nits from me, but I like the approach.

  1. +++ b/group.module
    @@ -573,3 +574,35 @@ function _group_content_enabler_manager() {
    +/**
    + * Implements hook_view_presave().
    + *
    + * @todo Remove in 8.2.x if it still only fixes cache contexts by then.
    + */
    +function group_view_presave(ViewEntityInterface $view) {
    

    Technically this is hook_ENTITY_TYPE_presave() that typehints EntityInterface.

  2. +++ b/group.module
    @@ -573,3 +574,35 @@ function _group_content_enabler_manager() {
    +        $cache_metadata['max-age'] = -1;
    

    Could be \Drupal\Core\Cache\CacheBackendInterface::CACHE_PERMANENT

catch’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.13 KB
6.41 KB

Fixing nits in #58. Since those are minor changes, going ahead and re-RTBCing.

kristiaanvandeneynde’s picture

Status: Reviewed & tested by the community » Fixed

Cheers, back to fixed. Removed the unused ViewsInterface use statement.

Status: Fixed » Closed (fixed)

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