Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also clear static cache of EntityAccessControlHandler #226

Open
pfrenssen opened this issue Jun 22, 2020 · 0 comments · May be fixed by #227
Open

Also clear static cache of EntityAccessControlHandler #226

pfrenssen opened this issue Jun 22, 2020 · 0 comments · May be fixed by #227

Comments

@pfrenssen
Copy link
Collaborator

pfrenssen commented Jun 22, 2020

We are having an issue with the entity access cache containing stale items in Behat scenarios. The problem occurs in the following circumstances (all the following steps are executed in a single Behat scenario, i.e. in a single Drupal request)

  1. Use an entity type which implements EntityPublishedInterface does not implement RevisionableInterface.
  2. Create an unpublished entity.
  3. View the entity with a user which does not have permission to view unpublished entities.
  4. Publish the entity.
  5. View the entity again with the same user.

Expected result: the user should see the entity.
Actual result: the entity is invisible.

This is caused by the static cache of EntityAccessControlHandler. The access status of entities are cached using a cache ID that is comprised of the UUID or {entity_type_id}:{entity_id}. In case of a revisionable entity type the revision ID is also appended to the cache ID.

In the following circumstances this works fine:

  • When using Drupal through the UI - the static cache only lives as long as a single request, and on subsequent requests it is rebuilt. It is unlikely to hit stale caches in these circumstances.
  • When using revisionable entities the cache ID changes as soon as the entity is published, and the stale cache entry is never hit.

However in a case of using a non-revisioned entity inside a long running process such as a Behat test these stale caches become a problem.

Suggested solution: clear the EntityAccessControlHandler static cache in \Drupal\Driver\Cores\Drupal8::clearStaticCaches() so that developers can decide to clear the caches in a related step definition or hook.

pfrenssen added a commit to pfrenssen/DrupalDriver that referenced this issue Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant