Problem/Motivation
When using a entity reference and the user uses a large integer value or other wrong values, then PostgreSQL will throw an exception.
Steps to reproduce
Enter "example (test)" value to any entity autocomplete field.
The following exception will be thrown.
The website encountered an unexpected error. Please try again later.
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bigint: "test" LINE 5: ...('tags')) AND ("taxonomy_term_field_data"."tid" IN ('test')) ^: SELECT "base_table"."revision_id" AS "revision_id", "base_table"."tid" AS "tid" FROM "taxonomy_term_data" "base_table" INNER JOIN "taxonomy_term_field_data" "taxonomy_term_field_data" ON "taxonomy_term_field_data"."tid" = "base_table"."tid" WHERE ("taxonomy_term_field_data"."vid" IN (:db_condition_placeholder_0)) AND ("taxonomy_term_field_data"."tid" IN (:db_condition_placeholder_1)); Array ( [:db_condition_placeholder_0] => tags [:db_condition_placeholder_1] => test ) in Drupal\Core\Entity\Query\Sql\Query->result() (line 273 of core/lib/Drupal/Core/Entity/Query/Sql/Query.php).
Details
Drupal 10.1.x, PHP 8.2, PostgreSQL 15
Proposed resolution
Sanitize the user input for integer fields with entity reference selectors
Remaining tasks
TBD
User interface changes
None
Introduced terminology
None
API changes
None
Data model changes
None
Release notes snippet
None
For the committer
The changes to the .gitlab-ci.yml file need to be removed before merging!
| Comment | File | Size | Author |
|---|
Issue fork drupal-3372068
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
chi commentedComment #4
chi commentedThe alternative solution could be casting field entity ID to text in SQL query.
Comment #5
joseph.olstadHello @Chi, thank you for this fix, it works for me also. No longer a WSOD running psql with this situation .
I'm not quite sure on steps to reproduce in my case so I'll leave yours as it seems easier to reproduce.
This works on both psql 12 and psql 13
Fix applies to D9.5.x also.
Comment #6
niklanPatch for Drupal 10.3+
Comment #8
liam morlandThe patch in #6 would stop the error messages, but may end up hiding an underlying issue with entities that have non-integer IDs.
Comment #9
liam morlandComment #13
daffie commentedAdded fix by filtering out wrong values for integer fields.
Comment #14
daffie commentedI have updated the CR.
Disclosure: I have used AI for the PR.
Comment #15
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. The merge request has merge conflicts and cannot be merged. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #16
daffie commentedRebased the PR.
CI Pipeline is green again.
Back to NR.
Comment #17
joseph.olstadComment #19
longwaveNot sure this is the best place for this method, this feels like it could be useful for more subsystems and either at the field or database level.
Comment #21
joseph.olstadtests are running, check the results
Comment #22
joseph.olstadNot sure if the fails are related to the changes. @longwave, are you able to have a look?
Comment #23
joseph.olstadok so the new branch I created wasn't using the latest head of main. kind of surprised by that but ya thanks @lkmorlan