Problem/Motivation

In Drupal\views\Plugin\views\filter\Combine::query(), a condition has duplicate expression.

      if (!empty($field->field_alias) && !empty($field->field_alias)) {
        $fields[] = "$field->tableAlias.$field->realField";
      }

Proposed resolution

Rename the conditions (see the existing patch) :

if (!empty($field->tableAlias) && !empty($field->realField))

Issue fork drupal-2810985

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

GoZ created an issue. See original summary.

goz’s picture

Status: Active » Needs review
StatusFileSize
new1 KB
Anonymous’s picture

goz’s picture

You are right vaplas, i hadn't see this issue.

I'm not sure test expression is correct btw.

I don't see why we use $field->field_alias here. May be it's a legacy and test should be different.

Just looking at this piece of code, expressions should be more relevant with :

      if (!empty($field->tableAlias) && !empty($field->realField)) {
        $fields[] = "$field->tableAlias.$field->realField";
      }
Anonymous’s picture

Status: Needs review » Needs work

I agree with GoZ. I don't see any reason to use empty($field->field_alias), but we can leave it for compatibility.

// @todo: Do not check field_alias, if it is not useful. See https://www.drupal.org/node/2810985
if (!empty($field->field_alias) && !empty($field->tableAlias) && !empty($field->realField)) {
goz’s picture

If we could find someone who know if field_alias is useful, it will be better that letting condition and adding todo comment

goz’s picture

Issue tags: -Quick fix, -Quickfix
_Archy_’s picture

Assigned: Unassigned » _Archy_
_Archy_’s picture

Status: Needs work » Needs review
Issue tags: +Needs testing
StatusFileSize
new744 bytes

After looking at the code for a while, I can't see any reason why this check should be there.

It was added when the views was merged into core and hasn't changed since. Soon after the merge there was a commit for changing variable names to comply with coding standards (camel-case), but for unknown reason the property field_alias in FieldPluginBase wasn't changed (strange):

This

if (!empty($field->field_alias) && !empty($field->field_alias)) {
  $fields[] = "$field->table_alias.$field->real_field";
}

Became

if (!empty($field->field_alias) && !empty($field->field_alias)) {
  $fields[] = "$field->tableAlias.$field->realField";
}

But the if condition(that has the duplicate condition) didn't change since.

The combine filter query basically searches on fields that do have non-empty field_alias property. I've looked at the FieldPluginBase and found that the field_alias is defaulted to 'unknown'. Also looked at places where the field_alias could be set to anything that would evaluate to empty, but it seems to me that it always is not empty.
=> So if I am right the condition in the if will in every situation evaluate to TRUE.

Another strange thing is that every field is selectable when configuring the combine filter. The Combine::buildOptionsForm doesn't do this check. So the question would be why is the Combine::query doing the check => inconsistency.

I am uploading this patch (removing the conditionally field add) for testing.

Side note:

One big problem here is the lack of documentation(like for the field_alias), many violations of drupal 8 coding standards, unstructured code. I really think that the core views needs refactoring. Like for example Sql has 50+ phpcs warnings/errors. Also interfaces are wrongly implemented, many methods can hardly be followed.

Status: Needs review » Needs work

The last submitted patch, 9: views.module-removes_conditional_add-2810985-9-D8.3.x.patch, failed testing.

_Archy_’s picture

Okay, this failing is actually a good thing. The bad thing is that for me locally the failed tests don't fail. They actually do 0 passes 0 fails and 0 exceptions, which is strange. I will keep trying to make it fail.

_Archy_’s picture

So I forgot to put the ViewAjaxTest test in. This passes successfully, but all the others do 0 passes. Still these tests for me all appear to be passing, but something still goes wrong, as sometimes I get redirected to the test list from the result page and also noticed the AJAX error showing in between of test running page and result page. Might this be an issue whit testing (ran with the testing module)??

What is really strange is that all errors are related to JS/AJAX. I can't see how taking out the if connect to these problems :\. Would be nice if I could get it fail locally as I could much more easily track the problem..

_Archy_’s picture

Status: Needs work » Needs review
StatusFileSize
new671 bytes

As I still can't get these tests to fail, I'll try to go with consistency and check for the same thing that is checked when building the options field and when validating (clickSortable).

Maybe unrelated, but without change or with these changes when I do the tests I get a page where AJAX response is printed out between the test page and the result page. I can access it by running the test than going back one in the browser:

An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /batch?id=8&op=do_nojs&op=do
StatusText: OK
ResponseText: 
Welcome to Drupal Dev | Drupal Dev
Skip to main content
Toolbar items
Back to site
Manage

...

Status: Needs review » Needs work

The last submitted patch, 13: views.module-tries_consistency-2810985-13-D8.patch, failed testing.

Anonymous’s picture

I can't get these tests to fail too. My steps to reproduce:

1. apply patch #9.
2. run phantomjs (by /core/tests/README.md):
phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768 2>&1 >> test.log
3. separate run phpunit for GlossaryViewTest, ClickSortingAJAXTest, ExposedFilterAJAXTest, PaginationAJAXTest.

All tests passed.

Also i not found different between phantomjs log with/without patch #9 (except time and hash, of course).

4. install Testing module (simpletest)
5. Run ViewAjaxTest
All tests passed too.

Anonymous’s picture

I ran patch #2 with php 7, but it still work without fails. It will be funny if the result we really only remove duplicate expression :)

csheltonlcm’s picture

I don't have an answer, but I might be able to point someone in the right direction.

I tried running this locally and got the same failures that the testbot did; I noticed some error messages in my apache log files:

[Mon Oct 24 17:16:06.943125 2016] [negotiation:error] [pid 18526] [client 127.0.0.1:55974] AH00687: Negotiation: discovered file(s) matching request: /var/www/drupal-issues/2810985/views (None could be negotiated)., referer: http://localhost/drupal-issues/2810985/test-glossary

If I disable MultiViews (in my apache config), the tests pass fine. I have always had it on and have never had problems with running Drupal tests before.

Seems extremely unlikely, but it might be something to investigate.

csheltonlcm’s picture

Status: Needs work » Needs review
StatusFileSize
new744 bytes

Haha - I think the problem is actually the name of the patch - resubmitting the patch from #9 under a different name (if I understand correctly, #13 was a best-guess attempt at fixing the test errors, and #9 is the fix we actually want?). I think the "views." at the beginning of the file is confusing apache when multiviews is enabled (and it looks like it probably is on the testbot - http://cgit.drupalcode.org/drupalci_testbot/tree/containers/base/web-bas...)

_Archy_’s picture

Thank you @vaplas for confirming that it doesn't fail for you aswell.
@csheltonlcm I wouldn't have thought about that. You just saved me from spending even more time figuring out why the tests don't fail locally.

What is left to do is to decide whether we keep the patch #9 without the condition or the patch #13 with the clickSortable condition. I think we should most likely go with clickSortable, because it states in the Combine::buildOptionsForm that a field that doesn't have this might break the filter (going to investigate more on why tough).

$options = array();
foreach ($this->view->display_handler->getHandlers('field') as $name => $field) {
   // Only allow clickSortable fields. Fields without clickSorting will
   // probably break in the Combine filter.
   if ($field->clickSortable()) {
       $options[$name] = $field->adminLabel(TRUE);
   }
}

But it's arguable as the user can only select these type of fields.
I am re-uploading the #13 patch just in case.

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.

joelpittet’s picture

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

Why they would "probably break" is a key question on keeping that clickSortable() and needs a comment around why.

lendude’s picture

Issue tags: -Needs testing +Needs tests

Closed #2882841: Combine fields filter includes a duplicate condition in if() statement as a duplicate of this. I like the patch we have there better, because in the if() we are actually testing for the variables we are using inside the if().

Background on the clickSortable usage in Combine: #2401953: Database exception for View with Combined field filter with fields with no query alias, short answer: it's waiting for #2349465: Add an isComputed method to field handlers to land.

joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new833 bytes

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.

xmacinfo’s picture

Issue summary: View changes
xmacinfo’s picture

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

As far I can tell, this should be RTBC, unless those conditions are always true.

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.

daffie’s picture

The patch from comment #24 is for me the correct solution (RTBC). We still need testing for this issue.

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

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.

Anonymous’s picture

Version: 8.6.x-dev » 8.8.x-dev
amit.drupal’s picture

Test patch #24 on 8.8.x-dev.
Patch is apply clearly, this is ready for RTBC .

daffie’s picture

Status: Needs review » Needs work

This issue needs automated tests.

shubham.prakash’s picture

Status: Needs work » Needs review
StatusFileSize
new707 bytes

This patch will fix the issue.

daffie’s picture

Status: Needs review » Needs work

@ shubham.prakash: Your patch is a copy fom the patch from comment #24.

This issue needs automated tests.

indrapatil’s picture

Issue summary: View changes
lendude’s picture

Reverted the issue back to before the edit in #36 which deleted all the info in the IS.

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.

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.

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.

rakhi soni’s picture

Status: Needs work » Needs review
StatusFileSize
new707 bytes

Kindly review patch for version 9.5x,,

smustgrave’s picture

Status: Needs review » Needs work

Moving back to needs work for the test cases

ayush.khare made their first commit to this issue’s fork.

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.

sahil rohilla01’s picture

Patch #44 tested and applied successfully for drupal 10.1.x version.

shubham chandra’s picture

StatusFileSize
new707 bytes

Added patch against #44 in Drupal 10.1.x

smustgrave’s picture

Patch #44 still applies for 10.1 so #49 was not needed. Updating credit.

smustgrave’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.72 KB
new1.87 KB
new2.56 KB

Lets see if this works.

smustgrave’s picture

The last submitted patch, 51: 2810985-51-tests-only.patch, failed testing. View results

andypost’s picture

Status: Needs review » Reviewed & tested by the community

test added and the fix is trivial

  • catch committed 0f5cb79 on 10.0.x
    Issue #2810985 by _Archy_, smustgrave, GoZ, joelpittet, csheltonlcm,...
  • catch committed 803264a on 10.1.x
    Issue #2810985 by _Archy_, smustgrave, GoZ, joelpittet, csheltonlcm,...
  • catch committed fee8436 on 9.5.x
    Issue #2810985 by _Archy_, smustgrave, GoZ, joelpittet, csheltonlcm,...
catch’s picture

Version: 10.1.x-dev » 9.5.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 10.1.x, cherry-picked to 10.0.x and 9.5.x, thanks!

I unchecked some commit credit where the patch uploaded was identical to the previous patch (and the previous patch still applied).

Status: Fixed » Closed (fixed)

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