On postgres 9.1 I have many errors in log that looks like:
PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "ct" LINE 5: WHERE (base.nid IN ('ct')) ^: 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] => ct ) w DrupalDefaultEntityController->load() (linia 196 z /includes/entity.inc).
This is related with postgresql casting. Postgresql can't cast 'ct' to integer.
Comment | File | Size | Author |
---|---|---|---|
#5 | 1932612_5_non_numeric_entity_ids.patch | 595 bytes | googletorp |
#1 | 1932612_1_non_numeric_entity_ids.patch | 556 bytes | googletorp |
Comments
Comment #1
googletorp CreditAttribution: googletorp commentedI've seen this problem - with all drupal entities that do loading from an url argument.
So if you fx go to user/foo, drupal will try to load the user with id "foo" which will cause an exception in Postgres - MySQL will instead silently fail and return 0 results.
A simple solution is to enforce numeric ids when loading entities. This is not strictly required to have numeric ids for entities, but the field system (and many other things) require entity ids to be numeric. So enforcing it in the default entity class: DrupalDefaultEntityController, should be just fine.
I've attached a simple patch that fixes the issue by removing all non numeric ids in the load function before doing anything.
Comment #3
googletorp CreditAttribution: googletorp commentedUpdate drupal version
Comment #4
googletorp CreditAttribution: googletorp commented#1: 1932612_1_non_numeric_entity_ids.patch queued for re-testing.
Comment #5
googletorp CreditAttribution: googletorp commentedUpdated the patch, to work when loading all entities.
Comment #6
scottm316 CreditAttribution: scottm316 commentedFixes the problem for me and I'm using postgres 8.4.16/Drupal 7.22.
Comment #7
PanchoThis is a duplicate of the D8 issue #1823494: Field API assumes serial/integer entity IDs, but the entity system does not, which seems to take the other direction allowing varchar IDs everywhere.
Let's see how this is solved there and then backport. I'm placing a note on the D8 issue.
Comment #8
ShadowMonster CreditAttribution: ShadowMonster commentedIt is still issue for 7.25 and changes from path must be applied
Comment #9
slippast CreditAttribution: slippast commentedThis issue is still hanging around in 7.26.
Good thing I noted this fix. This problem makes the Media module nearly impossible to use. On a side note, Drupal + Postgres = suffering.
Comment #10
Drupa1ish CreditAttribution: Drupa1ish commentedSorry to argue... Except this issue, Drupal 7 + Postgres works just fine, tested with a lot of modules. Even with Commerce Kickstart distribution is perfect.
Comment #11
stefan.r CreditAttribution: stefan.r commented5: 1932612_5_non_numeric_entity_ids.patch queued for re-testing.
Comment #12
stefan.r CreditAttribution: stefan.r commentedComment #13
leyonce CreditAttribution: leyonce commentedUsing commercekickstart7.x.2.20 with postgres 9.1 on ubuntu 12.04. Nice Patch! It worked beautifully. Thanks.
Comment #14
Liam MorlandComment #15
tobiasbI do not see the related issue therefore I re-opened this issue.
Comment #16
David_Rothstein CreditAttribution: David_Rothstein commented#7 points out that this is a duplicate of #1823494: Field API assumes serial/integer entity IDs, but the entity system does not, although I think it's really a duplicate of #1003788: PostgreSQL: PDOException:Invalid text representation when attempting to load an entity with a string or non-scalar ID instead. That issue is older and contains a patch that is farther along than this one (we can't completely assume that non-integer IDs are not allowed).
Comment #17
samsterlin CreditAttribution: samsterlin commentedThanks for the patch, It is working fine. patch
Comment #18
Drupa1ish CreditAttribution: Drupa1ish commentedComment #19
Drupa1ish CreditAttribution: Drupa1ish commentedComment #20
zaitsev CreditAttribution: zaitsev commentedWhere can I put this patch for fix this problem?
diff --git a/includes/entity.inc b/includes/entity.inc
index 2fefd59..e465b0b 100644
--- a/includes/entity.inc
+++ b/includes/entity.inc
@@ -158,6 +158,10 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface {
* Implements DrupalEntityControllerInterface::load().
*/
public function load($ids = array(), $conditions = array()) {
+ if (is_array($ids)) {
+ // Remvoe all non numeric ids.
+ $ids = array_filter($ids, 'is_numeric');
+ }
$entities = array();
// Revisions are not statically cached, and require a different query to
Is this the correct?