Steps to reproduce:

  1. Create or edit a view with multiple displays.
  2. In one display, add a relationship to another entity, and click "Apply (this display)" - the default option.
  3. Add a field, filter, or sort option that uses this relationship. Click "Apply (all displays)" - the default option

This will result in an error stating that the field you just added "uses a relationship that has been removed." This is confusing, because the relationship is present on the display you are currently editing. The error is actually referring to the other display(s) that have the field using the relationship but don't have the relationship (since that was only added to "this display"). Now you can't save the view until this error is resolved and the error does not make it clear what the problem is.

The error message could be improved to add the display that is causing the problem (i.e. "The {field} uses a relationship that is not present in {your other display}."). I'm assuming there is a good reason why "this display" is the default option for relationships but "all displays" is the default for fields. If not, perhaps the solution is to make "all displays" the default for everything.

Comments

mmcdermott created an issue. See original summary.

megan_m’s picture

Issue summary: View changes

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.

abarrio’s picture

Assigned: Unassigned » abarrio
Issue tags: +DevDaysSeville

Reproduced in Drupal core 8.4.x-dev.

I will try it.

abarrio’s picture

I think a message like 'The {filter} uses a relationship that is not present in any display' which is more explicative.

abarrio’s picture

Status: Active » Needs review
abarrio’s picture

Assigned: abarrio » Unassigned
andriy_novak’s picture

Status: Needs review » Reviewed & tested by the community

Fixed

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
@@ -2458,7 +2458,7 @@ public function validate() {
+          $errors[] = $this->t('The %handler_type %handler uses a relationship that is not present in any display.',['%handler_type' => $handler_type_info['lstitle'],'%handler' => $handler->adminLabel()]);

Reading the steps to reproduce it appears that the relationship is present in at least one display so I'm not sure the "in any display" is correct either.

alexpott’s picture

@andriy_novak thank you for reviewing this issue! A short RTBC message liked "Fixed" from a first time commenter on the issue leaves a lot on the committer to check.

What we do need people to review is whether the issue has a correct scope, whether it passes the core gates, whether the solution completely fixes the problem without introducing other problems, and whether it's the best solution we can come up with. See the patch review guide for more information.

When you do post a review, be sure to describe what you reviewed and how. This helps other reviewers understand why you considered the issue RTBC (and is considered for issue credit).

abarrio’s picture

Status: Needs work » Needs review
StatusFileSize
new2.38 KB

Hi @alexpott thanks for review message. I agree with you and I think a message like '... uses a relationship which is not present in all displays' would be better.

alexpott’s picture

+++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
@@ -2458,7 +2458,7 @@ public function validate() {
-          $errors[] = $this->t('The %handler_type %handler uses a relationship that has been removed.', ['%handler_type' => $handler_type_info['lstitle'], '%handler' => $handler->adminLabel()]);
+          $errors[] = $this->t('The %handler_type %handler uses a relationship which is not present in all displays.',['%handler_type' => $handler_type_info['lstitle'],'%handler' => $handler->adminLabel()]);

Whilst we're improving the message - do we think it is worth telling the user which relationship is missing?

abarrio’s picture

I think it would be a good idea to help user to find which realtionship cause that error.

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.

estoyausente’s picture

The error still happens in 8.5.6 (I mean, this f*** error in which I lost 2 hours, still happens in Drupal 8.5.6).

The patch seems correct, thanks @megan_m for the report and all collaborators for the fix. I think that we can add the relationship name and the display name that cause the error.

Something like:

    $display = $this->view->getDisplay();
    $display_name = $display->display['display_title'];

$errors[] = $this->t('The %relationship_name relationship used in %handler_type %handler is not present in %display_name', ['%relationship_name' => $handler->options['relationship'], '%handler_type' => $handler_type_info['lstitle'], '%handler' => $handler->adminLabel(), '%display_name' => display_name]); 
joachim’s picture

Status: Needs review » Needs work
+++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
@@ -2458,7 +2458,7 @@ public function validate() {
+          $errors[] = $this->t('The %handler_type %handler uses a relationship which is not present in all displays.',['%handler_type' => $handler_type_info['lstitle'],'%handler' => $handler->adminLabel()]);

I don't think this message will always be correct either.

What about the case the original message covers, where a relationship is deleted?

+1 to the suggestion in #17.

(Also, missing space after the comma.)

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.

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.

lendude’s picture

Status: Needs work » Needs review
Issue tags: +Bug Smash Initiative
StatusFileSize
new26.76 KB
new2.96 KB

Yeah #17 sounds pretty good, updated the patch and the test to use that. Also updated the test not to use t().

The end result looks something like this:

lendude’s picture

StatusFileSize
new2.93 KB

Added a period to the end of the error.

lendude’s picture

StatusFileSize
new2.96 KB

And now with the patch attached.....

joachim’s picture

Status: Needs review » Needs work

LGTM.

Though, just a nitpick -- I would split the array in the t() over multiple lines for readability.

+++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
@@ -2522,7 +2522,7 @@ public function validate() {
+          $errors[] = $this->t('The %relationship_name relationship used in %handler_type %handler is not present in %display_name.', ['%relationship_name' => $handler->options['relationship'], '%handler_type' => $handler_type_info['lstitle'], '%handler' => $handler->adminLabel(), '%display_name' => $this->display['display_title']]);

I think this should say '%display_name display', as the display name isn't always clear to understand in a sentence.

And a nitpick: the t() array would be more readable split over multiple lines now that it's so much longer.

lendude’s picture

Status: Needs work » Needs review
StatusFileSize
new3.03 KB
new3.06 KB

Thanks for the review! Changes sound good, implemented here.

Edit: Oh didn't do the multiline thing for the test, but it's a test so ¯\_(ツ)_/¯

ranjith_kumar_k_u’s picture

StatusFileSize
new3.05 KB
new660 bytes
joachim’s picture

Status: Needs review » Reviewed & tested by the community

LGTM!

larowlan’s picture

Status: Reviewed & tested by the community » Needs review

The code looks good, just wondering however if we can auto-detect the user is about to do this and prevent them from adding the field/filter/sort to 'all displays' when the relationship doesn't exist on the given display? i.e preventing the foot gun rather than warning about it? If that sounds like a follow-up task/feature, please put back to RTBC @Lendude

estoyausente’s picture

Honestly, I think that the current solution fixed the original bug "a confusing message" and it's quickly to be applied.

Maybe is better to close the issue right now with a valid solution and open a new one to discuss if we can manage the situation of another way.

abarrio’s picture

Status: Needs review » Reviewed & tested by the community

I agree with #34.
I think we should close this to fix the situation and discuss it in a new issue.

lendude’s picture

@larowlan I get what you are saying, but I think I remember this was discussed when we added this message too. Views had always allowed you to shoot yourself in the foot (and any other body part you can think of...). People have all sorts of different workflows when working on Views and not allowing them to do something that can be fixed later will mess with peoples workflow and lead to annoyance when we stop allowing people to work the way they are used to.

So I think we should hold to the pattern that we allow site builders to do what they want.

  • catch committed e7f6417 on 10.0.x
    Issue #2796045 by Lendude, abarrio, ranjith_kumar_k_u, megan_m, joachim...
  • catch committed 5d4b11b on 10.1.x
    Issue #2796045 by Lendude, abarrio, ranjith_kumar_k_u, megan_m, joachim...
  • catch committed 81aeb3c on 9.5.x
    Issue #2796045 by Lendude, abarrio, ranjith_kumar_k_u, megan_m, joachim...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Yeah I agree with the replies here, this normally happens when you have a mismatch between 'default' and 'overridden' for different parts of the view, and we can't know whether it's the fields or the relationships where the mistake is, so just informing people seems better than validating - knowing you need to click out, go and change something elsewhere, then click back into make the change isn't necessarily straightforward for people.

Committed/pushed to 10.1.x, cherry-picked to 9.5.x and 9.4.x. Since it's a string change, leaving the 9.4.x backport. Thanks all!

Status: Fixed » Closed (fixed)

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