Problem/Motivation

After updating to 10.2 all drush commands have been running into

Circular reference detected for service "current_user", path: "current_user -> msqrole.manager -> token -> current_user".

Steps to reproduce

Setup a 10.2 environment
Try installing this module
See error.

Proposed resolution

Believe the problem is this module declares a service called current_user which core does too.

Change current_user to msqrole.current_user

Remaining tasks

Rview

User interface changes

NA

API changes

Service name change

Data model changes

NA

Issue fork msqrole-3409535

Command icon 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

smustgrave created an issue. See original summary.

smustgrave’s picture

Status: Active » Needs review

Normally would recommend deprecating this service but it doesn't install at all on 10.2 so if we REALLY wanted to deprecate. Would have to fix the current version to <=10.1 and deprecate the service, start a new branch with the service name changed.

randalv’s picture

Assigned: Unassigned » randalv
Status: Needs review » Needs work

Hi @smustgrave,

Thank you for the report.

Sadly, renaming the service would partly nullify this module's functionality.
We need to override the account proxy object so the active roles are taken into account by anyone addressing the `current_user` service.

If we didn't do this, calling \Drupal::service('current_user')->getRoles(); would just return the configured roles for that user rather than the roles selected in Msqrole.

Currently, the token service is used in msqrole.manager to allow for tokens in the custom cache tags to be invalidated.
Maybe this is not needed, the less services we can have msqrole.manager depend on, the less situations could lead to circular references.

So essentially I see two possible solutions..

  1. Remove token dependency in the msqrole.manager service (and perhaps more if possible)
  2. Don't add the msqrole.manager service via the service arguments in the overridden `current_user` service

I do not have the time right now, but I'll do some testing to see what works best performance wise etc, and will push a solution ASAP.

smustgrave’s picture

Status: Needs work » Needs review

Removed token dependency.

smustgrave’s picture

Status: Needs review » Needs work

NW

smustgrave’s picture

Status: Needs work » Needs review

Removed variable from RoleManager, initial quick testing seems to still be working.

papagrande’s picture

Status: Needs review » Needs work

I tried to apply the patch from MR!4 and it failed. I'm very confused because the patch I downloaded from Gitlab doesn't look the same as https://git.drupalcode.org/project/msqrole/-/merge_requests/4/diffs#note....

smustgrave’s picture

Status: Needs work » Needs review

It applies cleanly to the dev branch, that can be seen in the MR. If you’re using a tagged version that may not apply.

papagrande’s picture

Ah, thanks. I forgot about updating to the dev version.

The patch applies and the error goes away. Beyond that, I don't know this module well enough to properly review the changes.

randalv’s picture

Assigned: randalv » Unassigned
Status: Needs review » Fixed

Sorry for the delayed response.

Thanks for giving a good start on the merge request, I did have to alter some more stuff (removing the dependencies on token etc).

I added a new tagged release (1.0.13) that should fix this!

Status: Fixed » Closed (fixed)

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