Follow up to PostgreSQL: PDOException:Invalid text representation when attempting to load an entity with a string or non-scalar ID.

In comment #256 @soyarma was right, the revision id needs to be cleaned as well. I came across this issue with the webform module. The error in watchdog was:

PDOException: SQLSTATE[22018]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Conversion failed when converting the varchar value 'configure' to data type int.: SELECT revision.[vid] AS [vid], base.[uid] AS [uid], revision.[title] AS [title], revision.[log] AS [log], revision.[status] AS [status], revision.[comment] AS [comment], revision.[promote] AS [promote], revision.[sticky] AS [sticky], revision.[vuuid] AS [vuuid], revision.[ds_switch] AS [ds_switch], base.[nid] AS [nid], base.[type] AS [type], base.[language] AS [language], base.[created] AS [created], base.[changed] AS [changed], base.[tnid] AS [tnid], base.[translate] AS [translate], base.[uuid] AS [uuid], revision.[timestamp] AS [revision_timestamp], revision.[uid] AS [revision_uid] FROM node base INNER JOIN node_revision revision ON revision.nid = base.nid AND revision.vid = :revisionId WHERE ( ([base].[nid] IN (:db_condition_placeholder_0)) ); Array ( [:db_condition_placeholder_0] => 86475 [:revisionId] => configure ) in DrupalDefaultEntityController->load() (line 198 of E:\KDN\includes\entity.inc).

Unfortunately the patch at #16 is not resolving it.

Comments

jordanrussellsmith created an issue. See original summary.

jordanrussellsmith’s picture

Status: Active » Needs review
StatusFileSize
new1.97 KB

Here is a patch for D7 that solved the issue for me.

BTW its my first patch on drupal.org so go easy on me ;)

Status: Needs review » Needs work

The last submitted patch, 2: 2732621-1.patch, failed testing.

jordanrussellsmith’s picture

Can someone offer some insight on how to get these tests to pass?

Thanks,
Jordan

David_Rothstein’s picture

Version: 7.43 » 7.x-dev

Thanks for the patch!

If you click through on the failed test results it will take you to a page with more details (in this case https://www.drupal.org/pift-ci-job/299059) which can help give information about why the test is failing.

In this case it looks like most of the failures are the following:

[Warning] Line 260 of includes/entity.inc:
array_map(): Argument #2 should be an array

From looking at the patch, I think a likely cause of this is that the cleanIds() method expects to be passed an array, but it isn't getting one from the new code added here?

David_Rothstein’s picture

By the way, this issue might also need to be moved to Drupal 8 and fixed there first (at least if #1003788-256: PostgreSQL: PDOException:Invalid text representation when attempting to load an entity with a string or non-scalar ID is correct that this affects Drupal 8 too; I haven't checked myself).

jordanrussellsmith’s picture

StatusFileSize
new2.01 KB

I added $revision_id to a new array $revision_ids to try to get the tests to pass...

jordanrussellsmith’s picture

Status: Needs work » Needs review
willzyx’s picture

StatusFileSize
new1.96 KB

rerolled

willzyx’s picture

StatusFileSize
new3.12 KB
+++ b/includes/entity.inc
@@ -188,6 +188,12 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface {
@@ -248,6 +254,13 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface {

@@ -248,6 +254,13 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface {
         $ids = array_map('intval', $ids);
       }
     }
+    if (isset($entity_info['revision table field types'])) {
+      $id_type = $entity_info['revision table field types'][$this->idKey];
+      if ($id_type == 'serial' || $id_type == 'int') {
+        $ids = array_filter($ids, array($this, 'filterId'));
+        $ids = array_map('intval', $ids);
+      }
+    }
   }

mmm place this check in DrupalDefaultEntityController::cleanId() not seems correct to me. I think that we need a separate method for check the revision id validity or otherwise the validation logic could be incorrect.. we risk to check revision id validity using the base table id definition (and vice versa)

Also probably is worth to check revision id validity also in DrupalDefaultEntityController::buildQuery() that is called directly by the subclasses

willzyx’s picture

StatusFileSize
new19 bytes

and the interdiff

willzyx’s picture

StatusFileSize
new2.04 KB

ehmm and the real interdiff :)

willzyx’s picture

StatusFileSize
new3.08 KB

rerolled

Status: Needs review » Needs work

The last submitted patch, 13: pdoexception-2732621-13.patch, failed testing. View results

joseph.olstad’s picture

Status: Needs work » Needs review

testbot is fixed

willzyx’s picture

StatusFileSize
new3.08 KB

rerolled

featherbelly’s picture

Issue summary: View changes

I get a similar error when adding a webform component using PostgreSQL — the revisionId is being set as components.

PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "components" LINE 4: ...ion ON revision.nid = base.nid AND revision.vid = 'component... ^: SELECT revision.vid AS vid, base.uid AS uid, revision.title AS title, revision.log AS log, revision.status AS status, revision.comment AS comment, revision.promote AS promote, revision.sticky AS sticky, revision.vuuid AS vuuid, revision.ds_switch AS ds_switch, base.nid AS nid, base.type AS type, base.language AS language, base.created AS created, base.changed AS changed, base.tnid AS tnid, base.translate AS translate, base.uuid AS uuid, revision.timestamp AS revision_timestamp, revision.uid AS revision_uid FROM {node} base INNER JOIN {node_revision} revision ON revision.nid = base.nid AND revision.vid = :revisionId WHERE (base.nid IN (:db_condition_placeholder_0)) ; Array ( [:db_condition_placeholder_0] => 126598 [:revisionId] => components ) in DrupalDefaultEntityController->load() (line 198 of /var/www/html/includes/entity.inc).

The patch at #16 does not solve this.

if (isset($entity_info['revision table field types'])) { ... } returns null in this instance.

protected function cleanRevisionId($id) {
    $entity_info = entity_get_info($this->entityType);
    if (isset($entity_info['revision table field types'])) {
      $id_type = $entity_info['revision table field types'][$this->idKey];
      if ($id_type == 'serial' || $id_type == 'int') {
        return $this->filterId($id) ? $id : FALSE;
      }
    }
    return $id;
  }
featherbelly’s picture

Sorry ignore me — didn't drush cc all. School boy error :-0

Patch works!

featherbelly’s picture

Status: Needs review » Closed (won't fix)
featherbelly’s picture

Status: Closed (won't fix) » Needs review

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.