-
Notifications
You must be signed in to change notification settings - Fork 179
Description
Since upgrading to 4.1, a "setcontent" clause with an order by is causing a SQL exception.
Details
| Question | Answer |
|---|---|
| Relevant Bolt Version | 4.1.0 |
| Install type | Composer install |
| BC Break | yes |
| PHP version | 7.4 |
| Web server | Nginx |
| For UX/UI issues | Firefox on Mac OS |
Reproduction
Bug summary
Including an orderby clause in setcontent is throwing a SQL exception in Bolt 4.1.0 (with latest dependencies installed using composer update.)
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 'TEXT)) ASC) dctrn_result) dctrn_table' at line 1").
Specifics
On my home page template, I am using "setcontent" to render the last 6 items of content type "reviews" in descending order based on the "date" field.
My content type:
reviews:
name: Reviews
singular_name: Review
fields:
name:
type: text
label: Person's name who left the review
body:
type: redactor
label: Content of the review
date:
type: date
mode: datetime
label: Date/time the review was posted
link:
type: text
label: Link to see the review (optional)
icon_many: "fa:users"
icon_one: "fa:users"
The twig tag:
{% setcontent reviews = 'reviews' limit 6 orderby '-date' %}
This worked correctly in 4.0.1, but is throwing the following exception in 4.1.0:
An exception has been thrown during the rendering of a template ("An exception occurred while executing 'SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id_0 FROM (SELECT b0_.id AS id_0, b0_.content_type AS content_type_1, b0_.status AS status_2, b0_.created_at AS created_at_3, b0_.modified_at AS modified_at_4, b0_.published_at AS published_at_5, b0_.depublished_at AS depublished_at_6 FROM bolt_content b0_ LEFT JOIN bolt_field b1_ ON b0_.id = b1_.content_id AND b1_.type IN ('generic', 'email', 'number', 'collection', 'date', 'filelist', 'textarea', 'set', 'data', 'text', 'image', 'html', 'file', 'hidden', 'checkbox', 'select', 'embed', 'templateselect', 'markdown', 'block', 'slug', 'imagelist', 'article', 'color', 'redactor') LEFT JOIN bolt_field_translation b2_ ON b1_.id = b2_.translatable_id WHERE b0_.content_type = ? AND b0_.status = ? AND b1_.name = ? ORDER BY LOWER(CAST(b2_.value AS TEXT)) ASC) dctrn_result) dctrn_table' with params ["reviews", "published", "date"]:
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 'TEXT)) ASC) dctrn_result) dctrn_table' at line 1").
The database is hosted on MariaDB 10.5.5, PHP 7.4.10.
Steps to reproduce
- Create a content type as above
- Create multiple items of that content type, making sure to specify the date
- Put the twig tag into a template (e.g. the home page template)
- View the page using the twig template (e.g. the home page)
Expected result
The tag would work, and something like {{ reviews|length }} would show the number of review items added.
Actual result
Exception as described above.
Switching the order by tag to ascending results in the same exception.
Removing the order by tag works but obviously the content is not ordered.