Skip to content

SQL rewriting by _node_query_node_access_alter is broken in MariaDB 11.x and higher #7186

Description

@herbdool

Description of the bug

Some of the exploration is in #Backdrop > Views' "Is none of" not playing nice with SQL rewriting though note that I discovered the problem is a bit more general.

Steps To Reproduce

Warning: I was experiencing this on a client site, but when I try to recreate this bug on a fresh site, I cannot. I can create a functionally identical query, but it shows all the items. (Perhaps the issue is needing a few more records? Is it that particular?) At any rate, I'll post the steps and query I've got.

To reproduce the behavior:

  • Create a content type: Team
  • Create a Paragraph type: Person (Presumably the bug would also be present if linking two content types via entity reference)
  • On Team add a Person field of paragraph field type: First, Last, Date Added custom fields.
  • Create a Taxonomy vocab: "Access" and some terms: "Editor"
  • On Team add a term reference field for that vocab.
  • Create a View with a block starting with the Team content type, contextual filter: Content ID of Team node, Relationship: Person field. Add fields for First, Last, Date Added (via relationships) and sort by Date Added.
  • Add the block to display on the layout to appear for Team nodes.
  • Enable some content access modules (I used Content View Access, Taxonomy Access).
  • Permit a role (e.g. editor) to have view access for Team in Content View Access, and set up Taxonomy Access so editor role can view content with the "Editor" term and authenticated cannot.
  • Create a Team node and add a bunch of persons.
  • As a test user with the editor role, view the Team node.
  • Additional testing: enable Devel, configure to display queries and give editor role permission to view Devel info.
SELECT
  `paragraphs_item_field_data_field_person`.`item_id` AS `paragraphs_item_field_data_field_person_item_id`,
  `paragraphs_item_field_data_field_person__field_data_field_date`.`field_date_value` AS `paragraphs_item_field_data_field_person__field_data_field_da`,
  'paragraphs_item' AS `field_data_field_first_name_paragraphs_item_entity_type`,
  'paragraphs_item' AS `field_data_field_last_name_paragraphs_item_entity_type`,
  'paragraphs_item' AS `field_data_field_date_paragraphs_item_entity_type`
FROM
  `node` `node`
  LEFT JOIN `field_data_field_person` `field_data_field_person` ON node.nid = field_data_field_person.entity_id
  AND (
    field_data_field_person.entity_type = 'node'
    AND field_data_field_person.deleted = '0'
  )
  LEFT JOIN `paragraphs_item` `paragraphs_item_field_data_field_person` ON field_data_field_person.field_person_value = paragraphs_item_field_data_field_person.item_id
  LEFT JOIN `field_data_field_date` `paragraphs_item_field_data_field_person__field_data_field_date` ON paragraphs_item_field_data_field_person.item_id = paragraphs_item_field_data_field_person__field_data_field_date.entity_id
  AND (
    paragraphs_item_field_data_field_person__field_data_field_date.entity_type = 'paragraphs_item'
    AND paragraphs_item_field_data_field_person__field_data_field_date.deleted = '0'
  )
WHERE
  (
    ((node.nid = '223'))
    AND(
      (
        (`node`.`status` = '1')
        AND (`node`.`type` IN ('team'))
      )
    )
  )
  AND (
    EXISTS (
      SELECT
        `na`.`nid` AS `nid`
      FROM
        `node_access` `na`
      WHERE
        (
          (
            (`na`.`gid` IN ('0'))
            AND (`na`.`realm` = 'all')
          )
          OR(
            (`na`.`gid` IN ('88'))
            AND (`na`.`realm` = 'cva_view_any_item')
          )
          OR(
            (`na`.`gid` IN ('88'))
            AND (`na`.`realm` = 'cva_view_any_unpublished_item')
          )
          OR(
            (`na`.`gid` IN ('88'))
            AND (`na`.`realm` = 'cva_view_any_page')
          )
          OR(
            (`na`.`gid` IN ('88'))
            AND (`na`.`realm` = 'cva_view_any_unpublished_page')
          )
          OR(
            (`na`.`gid` IN ('80'))
            AND (`na`.`realm` = 'cva_view_own_team')
          )
          OR(
            (`na`.`gid` IN ('80'))
            AND (`na`.`realm` = 'cva_view_own_unpublished_team')
          )
          OR(
            (`na`.`gid` IN ('1', '2'))
            AND (`na`.`realm` = 'taxonomy_access_role')
          )
        )
        AND (`na`.`grant_view` >= '1')
        AND (node.nid = na.nid)
    )
  )
ORDER BY
  paragraphs_item_field_data_field_person__field_data_field_da DESC
LIMIT
  5 OFFSET 0

Actual behavior

Only shows one item.

Expected behavior

Should show multiple items.

Additional information

Add any other information that could help, such as:

  • Backdrop CMS version:
  • PHP version: 8.3
  • Database sever (MySQL or MariaDB?) and its version: MariaDB 11.x and up

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions