Entity reference autocomplete in Paragraph causes SQL error when empty value is submitted

Created on 22 May 2025, 16 days ago

Problem/Motivation

I have a content type that includes a Paragraph.
Inside this Paragraph, there's an Entity Reference field with an Entity Autocomplete widget pointing to Block content.
When I try to add a new Paragraph to the content (e.g., via the node edit form), I get a SQL error in the logs related to a malformed query.
The issue occurs when the referenced value is an empty string ("") instead of a valid ID or a null value. The backend attempts to run a query with WHERE id IN (""), which causes a fatal PostgreSQL error.

SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bigint: ""
LINE 6: ...nload')) AND ("block_content_field_data"."id" IN ('')) AND (...

Steps to reproduce

  1. Create a Paragraph bundle with an Entity Reference field using Entity Autocomplete, targeting block_content.
  2. Add this Paragraph to a content type.
  3. Go to create or edit a node using that content type.
  4. Click "Add Paragraph"
  5. Observe the error in logs.

Proposed resolution

The autocomplete field handler or validation should ensure that empty string values are either:
* filtered out before querying, or
* converted to null, or
* the query should not run at all when the ID list is empty.

This will prevent malformed SQL from being sent to the database and improve compatibility, especially with PostgreSQL.

🐛 Bug report
Status

Active

Version

1.15

Component

Render element

Created by

🇫🇷France bakop Lille

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024