If you add a contextual filter "user has a revision" to a view, you will end with a broken SQL query preventing you to see the view result.

Steps to reproduce :

  • Create a new content view of all content types
  • Set the table style for formatting
  • Create a block for it
  • Add a contextual filter to your view called "User has a revision"
  • Set the default value to "provided default value" and set the value as "User ID from logged in user".
  • Check the preview zone, an SQL error should appear saying something like:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'node_field_data.revision_uid' in 'where clause': SELECT node_field_data.created AS node_field_data_created, node_field_data.nid AS nid FROM {node_field_data} node_field_data WHERE ((node_field_data.revision_uid = :node_field_data_uid_revision OR ((SELECT COUNT(DISTINCT vid) FROM {node_revision} nr WHERE nfr.revision_uid = :node_field_data_uid_revision AND nr.nid = node_field_data.nid) > 0))) AND (node_field_data.status = :db_condition_placeholder_0) ORDER BY node_field_data_created DESC LIMIT 5 OFFSET 0; Array ( [:node_field_data_uid_revision] => 1 [:db_condition_placeholder_0] => 1 ).

(I don't know if it should be considered major or not since i don't a workaround appliable here). Feel free to downgrade it if necessary.

Comments

Artusamak created an issue. See original summary.

artusamak’s picture

artusamak’s picture

Status: Active » Needs review
StatusFileSize
new986 bytes

The table name is broken for nfr so it's the first fix. The second fix refers to an unexisting uid_revision in the node_field_data table. The query conditions should be against the node_revision table.
Here is a fix for that.

artusamak’s picture

Here is the 8.2.x patch.

lendude’s picture

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

This fix would get this inline with the code in \Drupal\node\Plugin\views\filter\UidRevision so that looks good.

This still needs a test though.

artusamak’s picture

Status: Needs work » Needs review
StatusFileSize
new4.94 KB
new5.79 KB

Here is the test.
First patch is red to reproduce the issue, second patch is green with the fix.

The last submitted patch, 6: core-2858159-views_argument_revision-6-red.8.3.x.patch, failed testing.

lendude’s picture

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

@Artusamak nice! Looks really good already.

  1. +++ b/core/modules/node/src/Tests/Views/ArgumentUidRevisionTest.php
    @@ -0,0 +1,54 @@
    +class ArgumentUidRevisionTest extends NodeTestBase {
    

    Ideally this would be a kernel test. We are not using the browser at all, so we can save 30 seconds of test time by leaving the browser out of this. Something like \Drupal\Tests\node\Kernel\Views\NidArgumentTest should point out how you can set this up, the actual test bit you wrote should just work there too. Just setting up and generating the content is slightly different.

  2. +++ b/core/modules/node/src/Tests/Views/ArgumentUidRevisionTest.php
    @@ -0,0 +1,54 @@
    +  /**
    +   * Views used by this test.
    +   *
    +   * @var array
    +   */
    

    Nitpick: can just be {@inheritdoc}

artusamak’s picture

Status: Needs work » Needs review
StatusFileSize
new6.75 KB
new5.78 KB
new4.44 KB

Alright, just ask for it! Now it's converted. We will have to convert FilterUidRevisionTest which is almost the same test in a follow-up issue.

Here are the same tests going red and green with the fix but based on PHPUnit now.

The last submitted patch, 9: core-2858159-views_argument_revision-9-green.8.3.x.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 9: core-2858159-views_argument_revision-9-red.8.3.x.patch, failed testing.

lendude’s picture

@Artusamak++

+++ b/core/modules/node/tests/src/Kernel/Views/ArgumentUidRevisionTest.php
@@ -0,0 +1,93 @@
+namespace Drupal\node\Tests\Kernel\Views;

Needs to be namespace Drupal\Tests\node\Kernel\Views; the testbot actually cares about that and running it locally doesn't (unless you run it through run-tests.sh)

+++ b/core/modules/node/tests/src/Kernel/Views/ArgumentUidRevisionTest.php
@@ -0,0 +1,93 @@
+    $this->assertIdenticalResultset($view, $expected_result, ['nid' => 'nid'], 'Make sure that the view only returns nodes which match either the node or the revision author.');

We don't do error messages anymore, so that error string can be taken out.

artusamak’s picture

Thank you for the precious feedbacks. They are now included in the patch.

The last submitted patch, 13: core-2858159-views_argument_revision-13-red.8.3.x.patch, failed testing.

The last submitted patch, 13: core-2858159-views_argument_revision-13-green.8.3.x.patch, failed testing.

The last submitted patch, 13: core-2858159-views_argument_revision-13-red.8.3.x.patch, failed testing.

The last submitted patch, 13: core-2858159-views_argument_revision-13-green.8.3.x.patch, failed testing.

The last submitted patch, 13: core-2858159-views_argument_revision-13-red.8.3.x.patch, failed testing.

The last submitted patch, 13: core-2858159-views_argument_revision-13-red.8.3.x.patch, failed testing.

The last submitted patch, 13: core-2858159-views_argument_revision-13-green.8.3.x.patch, failed testing.

artusamak’s picture

Real green this time?

lendude’s picture

Status: Needs review » Reviewed & tested by the community

@Artusamak nice work. We have a fix and we have a test.

Queued tests for Postgres and sqlite to be on the safe side.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 21: core-2858159-views_argument_revision-21-green.8.3.x.patch, failed testing.

lendude’s picture

lendude’s picture

Status: Needs work » Reviewed & tested by the community

Retest passed, back to RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 21: core-2858159-views_argument_revision-21-green.8.3.x.patch, failed testing.

lendude’s picture

Status: Needs work » Reviewed & tested by the community

And more unrelated fails. And back to RTBC.

alexpott’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed fb8335a to 8.4.x and ed83d7e to 8.3.x. Thanks!

Great to see more and more views test coverage.

  • alexpott committed fb8335a on 8.4.x
    Issue #2858159 by Artusamak, Lendude: The "User has a revision" views...

  • alexpott committed ed83d7e on 8.3.x
    Issue #2858159 by Artusamak, Lendude: The "User has a revision" views...

Status: Fixed » Closed (fixed)

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