[PP-2] Workspace QueryFactory alters queries in a way that's not compatible with any other module doing the same

Created on 12 April 2023, over 1 year ago
Updated 8 March 2024, 9 months ago

Problem/Motivation

Workspaces module decorates core's query factory service, so that its own \Drupal\workspaces\EntityQuery\QueryFactory is used.

QueryFactory then overrides get() and getAggregate(). The result is that when a query class is obtained, if the required class exists in the Drupal\workspaces\EntityQuery namespace, then that query class is returned. If the class is not in Drupal\workspaces\EntityQuery, then the class in core's Drupal\Core\Entity\Query\Sql namespace is returned.

The problem is that nobody else can do this extension technique. If they do, then their custom Query class either:

- extends Drupal\workspaces\EntityQuery\Query, and then they have introduced a dependency on Workspaces module which is probably undesirable
- extends Drupal\Core\Entity\Query\Sql\Query, and then their customization is incompatible with Workspaces module, because whichever decoration of QueryFactory has priority will get to impose their class - either Workspaces or this custom module.

This means for instance that at 🐛 ContentEntity migration source doesn't consider the migration map Needs work we can't use this technique, because it would make migrations incompatible with workspaces.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Postponed

Version

11.0 🔥

Component
Workspaces 

Last updated 3 days ago

No maintainer
Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @joachim
  • 🇬🇧United Kingdom joachim

    Also, the workspaces QueryFactory extends from the original QueryFactory. That's a problem as well for other code that wants to do the same.

    The decorated QueryFactory should be injected, and called with $this->decorated->method() rather than parent::method().

  • 🇬🇧United Kingdom joachim

    This system for extending queries is documented in \Drupal\Core\Entity\Query\Sql\pgsql\QueryFactory:

     * To add a new query implementation extending the default SQL one, add
     * a service definition like pgsql.entity.query.sql and a factory class like
     * this. The system will automatically find the relevant Query, QueryAggregate,
     * Condition, ConditionAggregate, Tables classes in this namespace, in the
     * namespace of the parent class and so on. So after creating an empty query
     * factory class like this, it is possible to just drop in a class extending
     * the base class in this namespace and it will be used automatically but it
     * is optional: if a class is not extended the relevant default is used.
     *
     * @see \Drupal\Core\Entity\Query\QueryBase::getNamespaces()
     * @see \Drupal\Core\Entity\Query\QueryBase::getClass()
    

    Reading this, it sounds to me like the intention was that custom code could extend query classes for site-specific needs. It's designed as something that can be customised one time. It's not extensible by multiple modules, and workspace module having bagsied this functionality means nobody else can do it.

  • Status changed to Postponed 9 months ago
  • 🇷🇴Romania amateescu

    The way Workspaces entity query alter works might be improved after 📌 Add an alter hook to EntityQuery RTBC and #2502363: Add getters to EntityQuery , so postponing on those issues.

    FWIW, the Trash module has to do exactly what's described in the issue summary, and provide alternative EQ classes for both "vanilla" ones as well as the Workspace overrides :(

Production build 0.71.5 2024