Problem/Motivation

In QueryBase there are several functions: aggregate(), conditionAggregate(), sortAggregate(), and groupBy(), which contain {@inheritdoc}comments indicating that these functions are overrides of functions provided by the QueryAggregateInterface, but QueryAggregateInterface is not implemented by QueryBase.

Proposed resolution

Do one of the following:

  1. Fully implement the QueryAggregateInterface.
  2. Do not implement QueryAggregateInterface and rework the code in QueryBase.php.

All the patches so far (up to #15) use option 1, implement QueryAggregateInterface on QueryBase.

Remaining tasks

A decision is need on which of the two proposed resolutions should be used.
Additional analysis:

  1. Check the class hierarchy: are these methods declared in any parent class or interface?
  2. None found

  3. Check the classes that extend QueryBase. Do they implement QueryAggregateInterface?
  4. There are four classes the extend QueryBase, only Null implement QueryAggregateInterface

  5. (hard) See whether these methods are ever called.
  6. Try removing the methods and see whether any automated tests fail.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jibla’s picture

I am at DrupalCon LA. I will take care of this issue.

jibla’s picture

Status: Active » Needs review
FileSize
499 bytes

uploading the patch.

Status: Needs review » Needs work

The last submitted patch, 2: querybase-2489538-9927978.patch, failed testing.

jibla’s picture

new patch that passes through tests.

jibla’s picture

Status: Needs work » Needs review
mradcliffe’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
  1. +++ b/core/lib/Drupal/Core/Entity/Query/QueryBase.php
    @@ -488,4 +489,25 @@ public static function getClass(array $namespaces, $short_class_name) {
    +    // needs to be implemented
    ...
    +      // needs to be implemented
    ...
    +    // needs to be implemented
    

    I think these should have an @todo written for them following: https://www.drupal.org/coding-standards/docs#todo

    Is there a follow-up issue for implementing the code already, @drupaldeep?

  2. +++ b/core/lib/Drupal/Core/Entity/Query/QueryBase.php
    @@ -488,4 +489,25 @@ public static function getClass(array $namespaces, $short_class_name) {
    +  }  ¶
    

    There is a trailing white space here that should be removed.

This will need testing on all database systems.

xpsusa’s picture

benjifisher’s picture

Issue summary: View changes
Issue tags: +Needs beta evaluation

I expanded the issue summary and added the "Needs beta evaluation" tag. My guess is that, unless we find symptoms of this problem, it will not pass the beta evaluation.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

cilefen’s picture

Issue tags: -Needs beta evaluation
cristian100’s picture

Version: 8.1.x-dev » 8.2.x-dev
FileSize
2.24 KB

Rerolled patch against Drupal 8.2.x-dev and also updated code to drupal coding standard.

snehi’s picture

Status: Needs work » Needs review
andypost’s picture

Status: Needs review » Needs work

Looking through classes inherited from this I see \Drupal\Core\Entity\Query\Null\Query is the only one that implements this interface, so at least this one should be updated.

The other 2 ones \Drupal\Core\Config\Entity\Query\Query & \Drupal\Core\Entity\KeyValueStore\Query\Query does not care about aggreagation, so looks could inherit the same code from base class

  1. +++ b/core/lib/Drupal/Core/Entity/Query/QueryBase.php
    @@ -60,7 +60,7 @@
    -   * Aggregate Conditions
    +   * Aggregate Conditions.
    
    @@ -325,7 +325,7 @@ public function tableSort(&$headers) {
    -  function __clone() {
    +  public function __clone() {
    
    @@ -348,14 +348,14 @@ public function hasTag($tag) {
    -    return !(boolean)array_diff(func_get_args(), array_keys($this->alterTags));
    +    return !(boolean) array_diff(func_get_args(), array_keys($this->alterTags));
    ...
    -    return (boolean)array_intersect(func_get_args(), array_keys($this->alterTags));
    +    return (boolean) array_intersect(func_get_args(), array_keys($this->alterTags));
    
    @@ -448,7 +448,7 @@ protected function getAggregationAlias($field, $function) {
    -   * @param $object
    +   * @param object $object
    

    is out of scope, we deal with such issues in child issues of #2571965: [meta] Fix PHP coding standards in core

  2. +++ b/core/lib/Drupal/Core/Entity/Query/QueryBase.php
    @@ -483,4 +483,25 @@ public static function getClass(array $namespaces, $short_class_name) {
    +  public function existsAggregate($field, $function, $langcode = NULL) {
    +    // Needs to be implemented.
    ...
    +  public function notExistsAggregate($field, $function, $langcode = NULL) {
    +    // Needs to be implemented.
    ...
    +  public function conditionAggregateGroupFactory($conjunction = 'AND') {
    +    // Needs to be implemented.
    

    That's really debatable where implementation should live

radubutco’s picture

Assigned: Unassigned » radubutco
radubutco’s picture

Added the missing implementations in QueryBase for the methods added in the previous patch.
Removed the already implemented methods from one class which extends the QueryBase class.
Removed the implementing of QueryInterface and QueryAggregateInterface from the classes which extends the QueryBase class.

vladsocaciu’s picture

Assigned: radubutco » Unassigned
Status: Needs work » Needs review
Issue tags: +DevDaysMilan

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Title: QueryBase Methods Incorrectly Implements an Interface » QueryBase Methods Incorrectly Implements a QueryAggregateInterface
Issue summary: View changes
Issue tags: -Novice +Bug Smash Initiative
FileSize
3.78 KB
1.9 KB

Reading the issue there I don't see that there is agreement on which of the two proposed resolutions is to be implemented. All the patches seem to implement option #1 without any discussion. Because of that I am removing the novice tag.

A question was asked in #13.2 if three methods should be moved to QueryBase , that needs to be answered.

Despite all that, I choose to reroll that patch so that coding standard fixes to unrelated lines could be removed and make it easier to read.

And I did some research for two of the remaining tasks.
1) The methods are not declared in any parent class or interface.
2) There are four classes the extend QueryBase, only Null implement QueryAggregateInterface

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

BS Pavan’s picture

Tried to fix the failed test case.
Please review

daffie’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Entity/Query/Null/Query.php
@@ -22,25 +19,4 @@ public function execute() {
-    return new ConditionAggregate($conjunction, $this);

There is a missing use statement for the ConditionAggregate class.

quietone’s picture

Status: Needs work » Needs review
FileSize
409 bytes
3.96 KB

@daffie, thanks.

daffie’s picture

I do agree about moving the aggregate methods to the QueryBase class. To me it is the wrong place. When you a basic entity query the aggregate method should not be there. The best solution to me would be to create a new class called QueryAggregateBase which extends QueryBase and is the base class for all aggregate entity queries. Just my opinion, feal free to disagree.

When you call the first or the second moved methods from a basic entity query you will get an error, because the variable $this->conditionAggregate is null.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.