Problem

When you add a field that has no database column, like a Bulk Operation field, to a Combined field filter in Views, an exception is thrown.
For example, in the User admin View, modify the combined field filter to include the Bulk operation field, then search.

Proposed resolution

Since no sure way is available to determine which field will and won't work with this filter until something like #2349465: Add an isComputed method to field handlers becomes available, use clickSortable to at least filter away most (maybe even all) undesirables.

Remaining tasks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch, combine_field_filter_no_alias-SHOULDFAIL.patch, failed testing.

Lendude’s picture

Title: Database exception for View with Combined field filter with fields with not query alias » Database exception for View with Combined field filter with fields with no query alias
Status: Needs work » Needs review
FileSize
4.09 KB

And this should fix it.

this also removed the double check in the same setting

if (!empty($field->field_alias) && !empty($field->field_alias)) {
dawehner’s picture

+++ b/core/modules/views/src/Plugin/views/filter/Combine.php
@@ -64,7 +64,7 @@ public function query() {
-      if (!empty($field->field_alias) && !empty($field->field_alias)) {
+      if ($field->field_alias != 'unknown') {

AH! Good catch!

Don't we still need the !empty() check? Its better to be safe, you never know

Lendude’s picture

FileSize
683 bytes
4.13 KB

Since the default alias is 'unknown' (no idea why this isn't just FALSE or NULL, but it isn't), something would have to set this to something empty for this to occur, so don't know if that is something that would happen, but you are right, easy enough to still check, just in case.

Updated to patch to include the empty check.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Not sure honestly, but let's not try to change this, as this could have all kind of related changes.

Lendude’s picture

Related issues: +#2370251: Removed fields in Views Combined Filter setting lead to Fatal error

Now that I think about it....the problem that was raised by @alexpott with https://www.drupal.org/node/2370251 also might be an issue here.

With this fix, we silently skip over any fields in the filter config we don't like, with no warning to the end user that the config options are invalid/not used. So, I theory, the user could expect the view to be filtered by a certain value, but in fact it's not.

So do we need some kind of feedback on this? Or invalidate the View at some point?
I had a look at limiting the options array to fields with a field_alias, but aliases have not been set yet when buildOptionsForm() is called, so all aliases are 'unknown' at that point. So that's not something that can be used.

Any thoughts on this?

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

So how come a user can add such a field to a combined filter - surely the correct fix is to not list the fields that can not be filtered on.

Lendude’s picture

@alexpott I completely agree, but...

I had a chat with @dawehner on IRC about this as well and the problem is that it's impossible to detect which field will and which fields won't work at the time of building the options form. Like I said in #6, the criterium now used during query building can't be used because all aliases are 'unknown' at that time.

@dawehner said that when this feature was introduced it was accepted that it wouldn't work for some fields, the description for the field selector also says 'This filter doesn't work for very special field handlers.'
So to me it's now more about making sure that 'very special field handlers' are detected before exceptions are thrown. But unless we make every handler set a 'compatible with combine field filter' flag, I don't really see a criterium to test for during option building that would not give false positives or false negatives. If somebody else knows one, great!

But short of that, this is more about making sure people don't wind up facing an exception when we could have given them something more elegant.

Lendude’s picture

Status: Needs work » Needs review
FileSize
892 bytes
4.73 KB

Maybe abuse a different setting to test for a 'very special field handler'? If you can't click sort, you are probably dealing with something special right?

Not pretty, but gets the job done...

alexpott’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

How do we determine what to list on list of fields that can be a used as a normal filter? Also we need tests.

Lendude’s picture

@alexpott, sorry not quite sure what you mean by 'How do we determine what to list on list of fields that can be a used as a normal filter?'

dawehner’s picture

We could leverage the information from #2349465: Add an isComputed method to field handlers if that would land.

Lendude’s picture

@dawehner That sounds perfect! Maybe postpone this waiting for that to land? No idea what the odds are of that making it in though.

Lendude’s picture

Status: Needs work » Needs review

Lendude queued 9: 2401953-9.patch for re-testing.

Lendude’s picture

Issue summary: View changes
Issue tags: -Needs tests
FileSize
10.25 KB
9.38 KB

Rerolled and updated the patch a bit.

Since #2349465: Add an isComputed method to field handlers is an API change, that won't get into 8.0.x, so the 'misuse' of clickSortable, makes sense for 8.0.x I feel. Maybe add a follow up to update it to isComputed when that becomes available.

Edit: Some extra stuff got into the interdiff, ignore the error display stuff.

dawehner’s picture

+++ b/core/modules/views/src/Plugin/views/filter/Combine.php
@@ -108,6 +112,9 @@ public function validate() {
+      elseif (!$fields[$id]->clickSortable()) {
+        $errors[] = $this->t('Field %field set in %filter is not usable for this filter type.', array('%field' => $fields[$id]->adminLabel(), '%filter' => $this->adminLabel()));
+      }

We should try to explain why its not usable ...

Lendude’s picture

Added a comment with a @todo to the isComputed issue to indicate that this is a temp fix until there is something better to check.

Also made the error a bit more verbose.

Status: Needs review » Needs work

The last submitted patch, 18: 2401953-18.patch, failed testing.

Lendude’s picture

FileSize
9.73 KB

Duh, updated the message but not the test.....

Lendude’s picture

Status: Needs work » Needs review
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +String change in 8.0.2

Given that doing this throws a Database exception I think that doing this fix in 8.0.x makes sense and we should update the patch on #2349465: Add an isComputed method to field handlers to change the use of clickSortable() to isComputed().

Committed af13634 and pushed to 8.0.x and 8.1.x. Thanks!

  • alexpott committed 05b3abf on 8.1.x
    Issue #2401953 by Lendude, dawehner: Database exception for View with...

  • alexpott committed af13634 on
    Issue #2401953 by Lendude, dawehner: Database exception for View with...

Status: Fixed » Closed (fixed)

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