Problem/Motivation

Visiting the default (formerly master) display for the media_library view's configuration page results in a dblog/watchdog php notice. Well, two actually:

Notice: Undefined index: defaults in seven_views_pre_render() (line 351 of /var/lib/tugboat/stm/web/core/themes/seven/seven.theme)
and
Notice: Undefined index: defaults in media_library_views_pre_render() (line 181 of /var/lib/tugboat/stm/web/core/modules/media_library/media_library.module)

I imagine this is unlikely to be seen by most since it requires having the "Always show the master (default) display" checkbox checked (or set in settings.local.php or whatever), and I honestly don't know even know if it's really a problem that could cause any real-world issues, but since my team's development workflow includes checking the dblog for potential issues in every PR, I wasted some time thinking my edit to that view caused a bug/regression.

Steps to reproduce

  1. Enable (or have enabled) media and media_library.
  2. Go to /admin/structure/views/settings and check the "Always show the default display" checkbox. Save the page.
  3. Visit /admin/structure/views/view/media_library (and/or maybe just go directly to /admin/structure/views/view/media_library/edit/default without having to do the previous step?)
  4. Visit /admin/reports/dblog and see the two new notices.

Proposed resolution

Of course an isset() or array_key_exists() or whatever could be added to those lines in the .module and .theme files, though I don't know if maybe the default display ought to be getting that ['defaults'] key also fed to it instead? (Or maybe those classes should be added regardless of whether ['defaults'] exists or whatever? I don't quite know what all the two hook_views_pre_render()s are doing in the first place.)

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3217907

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

maxstarkenburg created an issue. See original summary.

mohit.bansal623 made their first commit to this issue’s fork.

mohit.bansal623’s picture

Status: Active » Needs review

isset conditions added in both .theme and .module files.

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

Drupal 9.1.10 (June 4, 2021) and Drupal 9.2.10 (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should 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.

kristen pol’s picture

Version: 9.3.x-dev » 9.4.x-dev
Issue tags: +Bug Smash Initiative, +Needs screenshots, +Needs manual testing

Thanks for the issue and MR.

1. Changing to 9.4.

2. Patch applies with offsets for Drupal 9.3, 9.4, and 10.

[drupal-9.3.x-dev/9.3.x] [drupal-9.3.x-dev]$ patch -p1 < 817.diff 
patching file core/modules/media_library/media_library.module
Hunk #1 succeeded at 176 (offset -2 lines).
patching file core/themes/seven/seven.theme
Hunk #1 succeeded at 347 (offset -1 lines).

[drupal-9.4.x-dev/9.4.x] [drupal-9.4.x-dev]$ patch -p1 < 817.diff 
patching file core/modules/media_library/media_library.module
Hunk #1 succeeded at 176 (offset -2 lines).
patching file core/themes/seven/seven.theme
Hunk #1 succeeded at 347 (offset -1 lines).

[drupal-10.0.x-dev/10.0.x] [drupal-10.0.x-dev]$ patch -p1 < 817.diff 
patching file core/modules/media_library/media_library.module
Hunk #1 succeeded at 176 (offset -2 lines).
patching file core/themes/seven/seven.theme
Hunk #1 succeeded at 347 (offset -1 lines).

3. Patch is very simple change.

4. Needs screenshots of before fix and after fix.

5. Needs manual testing on 9.4.

kmonahan’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs screenshots, -Needs manual testing
StatusFileSize
new500.11 KB
new565.5 KB
new107.38 KB

Tested on 9.4. Reproduced the issue following the steps in the ticket (see screenshots before1-3). Cleared the database log and applied the patch. Patch applied cleanly and reproduction steps no longer cause the issue (see screenshot after, showing the still-empty database log).

kmonahan’s picture

StatusFileSize
new115.05 KB
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

This points to the fact we have an untested code. It'd be great to add automated test coverage for it. \Drupal\Tests\media_library\FunctionalJavascript\ViewsUiIntegrationTest looks a good place to add it.

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
new1.28 KB

Kindly review patch for branch 9.5x,,

aarti zikre’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new122.43 KB
new48.06 KB

Verified on 9.5x dev drupal version. Now unable to reproduce the issue. Please check the below screenshot.
Steps performed :
1. Enable (or have enabled) media and media_library.
2. Go to /admin/structure/views/settings and check the "Always show the default display" checkbox. Save the page.
3. Visit /admin/structure/views/view/media_library
4. View the notices
5. Applied patch
6. follow step 3

Before patch
after patch

quietone’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

@aarti zikre, when adding screenshot please add them to the Issue Summary so it helps committers and reviewers find the latest. Not so important here as this issue only has a few comments so far but it does make a big difference on issues with many comments and sets of screenshots.

This is tagged as 'needs tests' and there are not tests in the patch. Tests were asked for in #9.

The proposed resolution section of the Issue Summary is full of questions. It should be a statement of what is being changed and why so the reviewer can determine that the intended fix was implements. Adding tag for an issue summary update.

smustgrave’s picture

Also seeing this issue with claro. So makes me think patching seven or theme isn't the approach.

smustgrave’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.96 KB
new2.75 KB
new2.88 KB

Adding a test. and added a line to the media_library.module that solves the warning without having to edit any of the themes.

Issue summary seemed clear to me (least the testing steps) so not sure if that label could be removed.

larowlan’s picture

Status: Needs review » Needs work
Issue tags: -Needs issue summary update +Needs tests

Still needs tests, see #9

smustgrave’s picture

Added a tests patch but looks like the regular one failed

smustgrave’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.78 KB
new3.24 KB
new2.7 KB

Took a different approach for the tests but should work.

The last submitted patch, 18: 3217907-18-tests-only.patch, failed testing. View results

Munavijayalakshmi’s picture

Assigned: Unassigned » Munavijayalakshmi
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new205.75 KB
new215.19 KB
new80.25 KB

Patch #18 resolved the issue.

Munavijayalakshmi’s picture

Assigned: Munavijayalakshmi » Unassigned
kristen pol’s picture

Status: Reviewed & tested by the community » Needs review

@Munavijayalakshmi Thanks for testing.

This still needs code review and core gate checks.

This does not need more manual testing, thanks!

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.

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

I wonder if this is a problem for all views, by default. Does Views simply not add the css_class key to the default display normally, and therefore any view would be affected by this problem, if it had a hook trying to access ['defaults']['css_class']?

Then again, Media Library is the module that's implementing hook_views_pre_view, so it should be acting more defensively. Therefore, I think this makes sense.

phenaproxima’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/media_library/tests/src/Functional/ViewsIntegrationTest.php
@@ -0,0 +1,64 @@
+    // Configure to always show the default display.
+    $edit = [
+      'ui_show_default_display' => TRUE,
+    ];
+    $this->drupalGet('admin/structure/views/settings');
+    $this->submitForm($edit, 'Save configuration');

Actually, one question: why do we need this section, or indeed, why does this need to be a functional test? We're rendering the view programmatically in this test, so in theory, wouldn't we get this error even if we weren't interacting with the UI?

smustgrave’s picture

Status: Needs review » Needs work

Moving to NW to convert test to a kernel test.

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new3.08 KB
new2.59 KB

Converted to kernel

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Assuming this passes tests, I like it.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
phpunit -c app/core app/core/modules/media_library/tests/src/Kernel/ViewsIntegrationTest.php 
Bootstrapped tests in 0 seconds.
PHPUnit 9.6.6 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\media_library\Kernel\ViewsIntegrationTest
.                                                                   1 / 1 (100%)

Time: 00:01.139, Memory: 10.00 MB

OK (1 test, 1 assertion)

Unfortunately that test doesn't fail without the fix

smustgrave’s picture

Status: Needs work » Needs review

So what is we go back to functional tests in #18 those do fail.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

I agree that #18 is a good solution. Code looks great and I can't find anything that needs to change.

The last submitted patch, 18: 3217907-18.patch, failed testing. View results

quietone’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/media_library/tests/src/Functional/ViewsIntegrationTest.php
@@ -0,0 +1,64 @@
+    unset($build['#view']->display_handler->options['defaults']);
+    // If this fails then there is a bug.
+    $this->assertNotNull($renderer->renderRoot($build));

Comments should help the user understand the test. For me, this is merely a statement of the obvious. As someone who does not know the render system this is meaningless.

Also, the title of this is an error message, can we change it to what is being fixed?

It is always challenging to decide to push back on such matters but these details help those who come behind us.

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.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.