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
| Comment | File | Size | Author |
|---|---|---|---|
| #34 | 1851398-34.patch | 2.33 KB | stefan.r |
| #31 | interdiff_27-31.txt | 311 bytes | heddn |
| #31 | entitycache-pdoexception_invalid-1851398-31.patch | 2.24 KB | heddn |
Comments
Comment #1
dave reidMarked #1795918: Can only flip STRING and INTEGER values! as a duplicate of this issue.
Comment #2
Renee S commentedThis patch worked for me.
eta: I take it back. It blew up some Views. Will investigate...
Comment #3
codycraven commentedThe 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.
Comment #4
gabriel.achille commented#0 works for me so far... I don't see any regression like #2. Will keep you posted if issue.
Comment #5
psf_ commentedHi 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.
Comment #6
tanius commentedAgreeing 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!:
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.
Comment #7
stefan.r commentedentitycache-numeric-ids.patch queued for re-testing.
Comment #8
claudiu.cristea#0 fixes the issue. RTBC.
Comment #9
smndey commentedThis patch worked for me. Thanks.
Comment #10
claudiu.cristea#0 works and is critical for PostgreSQL sites. Can we have this in please?
Comment #11
stefan.r commentedSorry 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
Comment #15
joelpittet@stefan.r that patch instantly gave me a WSOD.
And this on
drush cc allFollowed by this on registry rebuild:
drush rrComment #16
heddnAnother issue with #11 is it uses a lamda function. Unfortunately, that isn't so cool in older versions of PHP (< 5.3).
Comment #17
stefan.r commentedI'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.
Comment #18
claudiu.cristea#1003788: PostgreSQL: PDOException:Invalid text representation when attempting to load an entity with a string or non-scalar ID is in. So?
Comment #19
stefan.r commentedwe can just copypaste the cleanIds() from there -- though we'd then have a minimum drupal version requirement for entity cache.
Comment #20
stefan.r commentedmaybe we can only do the entity ID sanitization if people have drupal 7.36 and up?
Comment #21
socialnicheguru commentedjust a note: conflicts with RTBC https://www.drupal.org/node/1851398
Comment #22
stefan.r commentedComment #23
joelpittetIt may be good to log the error as it seems likely that there may be an error in code that is passing values up the stack. At least array_flip errors seem to be popping up like that for me;)
Comment #24
stefan.r commentedThis patch is just copying code from the core entity controller -- it simulates MySQL behavior by filtering out invalid IDs. Other database systems throw an exception.
If we were to log this, shouldn't we be fixing that in core first?
Comment #25
joelpittetProbably should be fixed in core, but 'first' is debatable, either case maybe it's a follow-up.
Comment #26
socialnicheguru commenteddrush rr --fire-bazooka
Error: Using $this when not in object context in
modules/all/entitycache/entitycache.module, line 167
Comment #27
stefan.r commentedcreated a follow-up issue at #2516094: Log an error when attempting to load an entity with a non-numeric ID
Comment #28
sgdev commented@stefan.r, I tested the patch in #27. It didn't fix our issue, but it did cause us to realize that there was a function error causing our problems.
However, I did want to inform you of a change that's needed in the patch. When making a dependency on Drupal, the typical way to do so is as follows:
The word "drupal" is not seen as a module name, and actually will cause Entitycache (and dependent modules) to becomes disabled because Drupal is seen as "missing." Thanks.
Comment #30
catchNow that this is in 7.x, I'm happy to commit the same code to entitycache, although looks like #28 needs fixing.
Comment #31
heddnComment #34
stefan.r commentedreroll
Comment #36
catchCommitted/pushed to 7.x-1.x, thanks!