Problem/Motivation

The following SQL error happens if a view contains "Has new content" filter and there are no any content types with comment field.

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '> (1445975102 - 2592000))) OR history.timestamp < node_field_data.changed OR his' at line 2: SELECT node_field_data.nid AS nid FROM {node_field_data} node_field_data LEFT JOIN {history} history ON node_field_data.nid = history.nid AND history.uid = :views_join_condition_0 WHERE (( ((history.timestamp IS NULL AND (node_field_data.changed > (1445975102 - 2592000) OR .last_comment_timestamp > (1445975102 - 2592000))) OR history.timestamp < node_field_data.changed OR history.timestamp < .last_comment_timestamp) )); Array ( [:views_join_condition_0] => 1 )

Proposed resolution

  • This errors happens if we have no comment type yet, which causes the relationship between the comment_entity_statistics table and the entity type to not be created yet by CommentViewsData.
  • Check whether the join to the table can be resolved before adding the filter condition

Remaining tasks

User interface changes

API changes

Data model changes

Why should this be committed before the RC

Pro

This fixes a fatal error, which always gives a bad sign for users about the state of Drupal itself.

Contra

This is just a normal bug which can be easily committed once 8.0.0 is out.

Comments

fomenkoandrey created an issue. See original summary.

cilefen’s picture

Title: Filer criterias for views, option "Content is updated" - error "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near" » Filter criteria for views, option "Content is updated" - causes a SQL syntax error
Version: 8.1.x-dev » 8.0.x-dev
Issue tags: +mariadb
fomenkoandrey’s picture

i hope, fixed first post. Thank U

cilefen’s picture

Do you mean the filter named "Content: Has new content"?

fomenkoandrey’s picture

When I select the Filter criteria option in the list:
i see in russian:

"Содержимое обновлено | Содержимое | Показывать только новые или обновленные материалы."

the translation would be something:

"Content updated | Content | Show only new or updated content."

because I chose updated content, this option is more likely to:

Content: Content updated

I do not know how to look the exact value in English.

cilefen’s picture

Thank you for translating. I tried that filter on a view of nodes and did not see the error you reported.

Can you post the database version you are running and any other possibly relevant details in the issue summary? And was this on the current Drupal 8.0.x HEAD from git?

Perhaps someone else can reproduce the issue.

fomenkoandrey’s picture

I installed the latest version of Drupal two days ago, i think from there https://www.drupal.org/project/drupal
of the extensions - only taxonomy menu, but it is not used.

from the report of Drupal :

Drupal 8.0.0-dev
Drupal core 8.0.0-rc1+6-dev (2015-Окт-09)
PHP 5.5.30
Web server Apache
database version 10.1.2-MariaDB-wsrep-log
database MySQL, MariaDB, Percona Server

System Linux skm71.hostsila.org 2.6.32-531.29.2.lve1.3.11.1.el6.x86_64 #1 SMP Thu Dec 18 06:49:17 EST 2014 x86_64
Build Date Oct 2 2015 14:49:36
Server API CGI/FastCGI

cilefen’s picture

Component: database system » views_ui.module

I moved this to the views_ui module, which is the Views management module.

dawehner’s picture

Component: views_ui.module » views.module
Issue tags: +Needs tests

views_ui is wrong, this is certainly views which causes the problem.

@fomenkoandrey Do you mind providing an export of the view

fomenkoandrey’s picture

StatusFileSize
new171.22 KB

I'm sorry, I did not understand the question.
view created in Drupal 8, do not be exported or imported.
I attach the screenshot.

fomenkoandrey’s picture

StatusFileSize
new50.48 KB

Do you mind providing an export of the view

added
lines 1374-1409

fomenkoandrey’s picture

the same error in RC2

chi’s picture

StatusFileSize
new3.99 KB

A simplified view to reproduce the bug.

chi’s picture

The error disappeared after attaching comment field to Article content type.

chi’s picture

Component: views.module » history.module
StatusFileSize
new1.04 KB
chi’s picture

Status: Active » Needs review
StatusFileSize
new562 bytes

should fail

Status: Needs review » Needs work

The last submitted patch, 16: test_only-2591147-16.patch, failed testing.

chi’s picture

Status: Needs work » Needs review
StatusFileSize
new1.59 KB
new1.59 KB

combined 15 and 16

chi’s picture

chi’s picture

chi’s picture

Issue summary: View changes
dawehner’s picture

Status: Needs review » Needs work

It would be great if someone could describe in the issue summary or better via a comment in the code why this ensureTable call could fail ...
Needs work as we need tests.

chi’s picture

Status: Needs work » Needs review
StatusFileSize
new1.69 KB

added a note

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests
+++ b/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php
@@ -82,9 +82,12 @@ public function query() {
+      // The table is not available if none of the content types has attached
+      // comment field.

Interesting, so we already have sort of a test coverage, great!

cilefen’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php
@@ -82,9 +82,12 @@ public function query() {
+      // The table is not available if none of the content types has attached
+      // comment field.

This should read "...has an attached comment field." or "... has attached comment fields.", whichever is more correct. Then, it can go right back to RTBC.

chi’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.69 KB

Back to RTBC per #25.

chi’s picture

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 26: 2591147-26.patch, failed testing.

The last submitted patch, 26: 2591147-26.patch, failed testing.

fomenkoandrey’s picture

the same error in RC3:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '> (1446791122 - 2592000))) OR history.timestamp < node_field_data.changed OR his' at line 2: SELECT COUNT(*) AS expression FROM (SELECT 1 AS expression FROM {node_field_data} node_field_data LEFT JOIN {history} history ON node_field_data.nid = history.nid AND history.uid = :views_join_condition_0 WHERE (( (node_field_data.status = :db_condition_placeholder_0) AND (node_field_data.type IN (:db_condition_placeholder_1)) AND ((history.timestamp IS NULL AND (node_field_data.changed > (1446791122 - 2592000) OR .last_comment_timestamp > (1446791122 - 2592000))) OR history.timestamp < node_field_data.changed OR history.timestamp < .last_comment_timestamp) ))) subquery; Array ( [:db_condition_placeholder_0] => 0 [:db_condition_placeholder_1] => article [:views_join_condition_0] => 1 )

chi’s picture

@fomenkoandrey, the patch is not commited yet.

dawehner’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community
Issue tags: +rc target triage

Its still green

@Chi
Do you think this has to be committed before 8.0.0? For me this is a normal bugfix, but let's see whether we can convince the core committers

chi’s picture

@dawehner, I was unaware that usual bugfixes are not allowed in release candidates. I do not understand the reason behind this but that won't be a big problem since D8 release is coming soon.

xjm’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -rc target triage +rc target
+++ b/core/modules/history/src/Tests/Views/HistoryTimestampTest.php
@@ -24,7 +24,7 @@ class HistoryTimestampTest extends ViewTestBase {
-  public static $modules = array('history', 'node');
+  public static $modules = array('history', 'node', 'comment');

So this is what provides the test coverage, but I have no indication as to why it's necessary for the comment module to be added in this test.

Can we either add an explicit test or at least a comment as to how it provides coverage? I'd prefer the former probably to decouple the coverage.

@effulgentsia and I agreed with both the points in the summary in terms of RC. This is indeed a bug that can be fixed in a patch release. Since it causes a fatal, though, that seems like an OK reason to make the change during RC since there is no disruption.

chi’s picture

Status: Needs work » Needs review
StatusFileSize
new922 bytes

Should fail.

chi’s picture

It looks for me that moduleExists('comment') is not needed here since we are checking comment_entity_statistics table.

Status: Needs review » Needs work

The last submitted patch, 35: 2591147-35-test_only.patch, failed testing.

chi’s picture

Status: Needs work » Needs review
StatusFileSize
new1.7 KB
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Well,

The last submitted patch, 35: 2591147-35-test_only.patch, failed testing.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.0.x, thanks!

  • catch committed ccd1f0b on 8.0.x
    Issue #2591147 by Chi: Filter criteria for views, option "Content is...
alexpott’s picture

Issue summary: View changes

  • catch committed ccd1f0b on 8.1.x
    Issue #2591147 by Chi: Filter criteria for views, option "Content is...

Status: Fixed » Closed (fixed)

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