Following on from the core conversation with the exact same name #1003788: PostgreSQL: PDOException:Invalid text representation when attempting to load an entity with a string or non-scalar ID is it possible to commit a fix to entity_cache directly to ensure only nodes with numeric IDs are loaded?

I have already patched core with #76, and this solves the issue for core, however entity_cache does it's own entity loading, and thus also suffers from the same symption.

Here is the error you get by visiting /node/add:

PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "add" LINE 5: WHERE (base.nid IN ('add')) ^: 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, 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, revision.timestamp AS revision_timestamp, revision.uid AS revision_uid FROM {node} base INNER JOIN {node_revision} revision ON revision.vid = base.vid WHERE (base.nid IN (:db_condition_placeholder_0)) ; Array ( [:db_condition_placeholder_0] => add ) in EntityCacheControllerHelper::entityCacheLoad() (line 100 of /var/www/drupal/mts-st/releases/20121127-6/modules/catalyst/entitycache/entitycache.module).

Patch attached, that is very similar to the core patch

Files: 
CommentFileSizeAuthor
#11 entitycache-1851398-10.patch1.92 KBstefan.r
FAILED: [[SimpleTest]]: [MySQL] 3,310 pass(es), 1,816 fail(s), and 724 exception(s).
[ View ]
entitycache-numeric-ids.patch1.2 KBwiifm
PASSED: [[SimpleTest]]: [MySQL] 5,828 pass(es).
[ View ]

Comments

Dave Reid’s picture

Status:Active» Needs review

Marked #1795918: Can only flip STRING and INTEGER values! as a duplicate of this issue.

Renee S’s picture

This patch worked for me.

eta: I take it back. It blew up some Views. Will investigate...

codycraven’s picture

The patch in #0 no longer reflects the latest patch #1003788: PostgreSQL: PDOException:Invalid text representation when attempting to load an entity with a string or non-scalar ID.

The newest patch from #1003788 actually looks a lot more like #1795918: Can only flip STRING and INTEGER values! #13 which was marked duplicate.

I think the right solution for the time being may be to simply wrap the array_flip parameter with array_filter as #1795918 did, until core is solved.

gabriel.achille’s picture

#0 works for me so far... I don't see any regression like #2. Will keep you posted if issue.

psf_’s picture

Hi All,

In Entity Cache 7.x-1.1 I see the same problem when somebody go to the URL /node/sites or similar.

PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: la sintaxis de entrada no es válida para integer: «sites» LINE 5: WHERE (base.nid IN ('sites')) ^: 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, 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, revision.timestamp AS revision_timestamp, revision.uid AS revision_uid FROM {node} base INNER JOIN {node_revision} revision ON revision.vid = base.vid WHERE (base.nid IN (:db_condition_placeholder_0)) ; Array ( [:db_condition_placeholder_0] => sites ) en EntityCacheControllerHelper::entityCacheLoad() (línea 95 de /var/www/html/sites/all/modules/entitycache/entitycache.module).

I think that if the node id is not a number the module must send a page not found message.

Thx by this great module.

tanius’s picture

Agreeing with #4: The patch in #0 works for me so far, no broken views. The proposal in #3 seems better, but at least some solution should make it into a release, no? ;)

For SEO reference, the error messages that the #0 patch fixed for me had been these – different from the original report, but similar to duplicate #1795918: Can only flip STRING and INTEGER values!:

Warning: array_flip(): Can only flip STRING and INTEGER values! in EntityCacheControllerHelper::entityCacheLoad() (line 69 of [...]/modules/contrib/entitycache/entitycache.module).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 350 of [...]/includes/entity.inc).

Repeated several times, and appearing esp. in Organic Group pages of groups. I use entitycache 7.x-1.2 as part of Drupal Commons 7.x-3.9.

stefan.r’s picture

entitycache-numeric-ids.patch queued for re-testing.

claudiu.cristea’s picture

Status:Needs review» Reviewed & tested by the community

#0 fixes the issue. RTBC.

somenathdey’s picture

This patch worked for me. Thanks.

claudiu.cristea’s picture

#0 works and is critical for PostgreSQL sites. Can we have this in please?

stefan.r’s picture

Status:Reviewed & tested by the community» Needs review
StatusFileSize
new1.92 KB
FAILED: [[SimpleTest]]: [MySQL] 3,310 pass(es), 1,816 fail(s), and 724 exception(s).
[ View ]

Sorry to butt into an issue that is already marked RTBC, but D8 has this fix already and a D7 backport is RTBC in core after a more extensive discussion (#1003788: PostgreSQL: PDOException:Invalid text representation when attempting to load an entity with a string or non-scalar ID).

Attached is that same core patch copy-pasted into Entitycache, it has more or less the same logic as #0

Status:Needs review» Needs work

The last submitted patch, 11: entitycache-1851398-10.patch, failed testing.

Status:Needs work» Needs review

Status:Needs review» Needs work

The last submitted patch, 11: entitycache-1851398-10.patch, failed testing.

joelpittet’s picture

@stefan.r that patch instantly gave me a WSOD.
And this on drush cc all

PHP Fatal error: Using $this when not in object context in sites/all/modules/contrib/entitycache/entitycache.module on line 95
Drush command terminated abnormally due to an unrecoverable error. [error]
Error: Using $this when not in object context in sites/all/modules/contrib/entitycache/entitycache.module, line 95

Followed by this on registry rebuild:
drush rr

PHP Fatal error: Using $this when not in object context in sites/all/modules/contrib/entitycache/entitycache.module on line 95
Drush command terminated abnormally due to an unrecoverable error. [error]
Error: Using $this when not in object context in sites/all/modules/contrib/entitycache/entitycache.module, line 95

heddn’s picture

Another issue with #11 is it uses a lamda function. Unfortunately, that isn't so cool in older versions of PHP (< 5.3).

stefan.r’s picture

I'll address this in #1003788: PostgreSQL: PDOException:Invalid text representation when attempting to load an entity with a string or non-scalar ID.. As soon as that patch goes in (if ever ;) it can be ported to Entity Cache.

stefan.r’s picture

we can just copypaste the cleanIds() from there -- though we'd then have a minimum drupal version requirement for entity cache.

stefan.r’s picture

maybe we can only do the entity ID sanitization if people have drupal 7.36 and up?