jhedstrom / DrupalDriver

A collection of drivers for controlling Drupal.
GNU General Public License v2.0
64 stars 95 forks source link

Also clear static cache of EntityAccessControlHandler #226

Open pfrenssen opened 4 years ago

pfrenssen commented 4 years ago

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:

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.