Problem/Motivation

On a site using PostgreSQL, deleting a custom block can lead to this error:

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bigint: "BLOCK_ID" LINE 5: ...rce_mapped_object"."drupal_entity__target_id" IN ('... ^: SELECT "base_table"."revision_id" AS "revision_id", "base_table"."id" AS "id" FROM "salesforce_mapped_object" "base_table" INNER JOIN "salesforce_mapped_object" "salesforce_mapped_object" ON "salesforce_mapped_object"."id" = "base_table"."id" WHERE ("salesforce_mapped_object"."drupal_entity__target_type" IN (:db_condition_placeholder_0)) AND ("salesforce_mapped_object"."drupal_entity__target_id" IN (:db_condition_placeholder_1)); Array ( [:db_condition_placeholder_0] => block [:db_condition_placeholder_1] => BLOCK_ID ) in Drupal\Core\Entity\Query\Sql\Query->result() (line 288 of core/lib/Drupal/Core/Entity/Query/Sql/Query.php).

This is because $entity->id() returns a value that is not an integer or integer string. PostgreSQL will not accept non-integer strings for the entity_id column because it is an integer column.

Steps to reproduce

On a site using PostgreSQL, call salesforce_mapping_entity_delete() with an entity that has an ID that is not an integer. This happens when deleting a custom block.

Proposed resolution

Check the type of the ID in salesforce_mapping_entity_delete() and return early if it is not an integer or integer string.

Remaining tasks

Implement.

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork salesforce-3589241

Command icon 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

liam morland created an issue. See original summary.

liam morland’s picture

Status: Active » Needs review
liam morland’s picture

Current state of merge request.

aaronbauman’s picture

Thank you for the patch, this is probably a good stopgap.

In theory, this module is meant to support entities with integer or string ids, via dynamic entity reference.
In practice, seems like there's no simple way to do that while maintaining a single table - salesforce_mapped_object - to record those references.

So, being that that's the case, I can see a couple different options to move this forward.

1) drop support for string ids. this would also allow us to ditch dynamic entity reference dependency.
seems like this wouldn't be that big a change, since support for string ids doesn't work anyway.

2) fix support for string ids. this would be much more involved.

liam morland’s picture

Yes, I agree it is a good idea to do the simple fix to prevent this error right away. It can be a feature to properly support entities with string keys.