One my test site, I enabled the module Flag and I'm testing out the "bookmarks" application, as a demo for getting used to the module. BTW I'm using Postgres as my database.
I have 1 node (of custom the content type "car") and a test user that bookmarked it. Now as that user I try to look at my bookmarks. Nothing fancy. I get a fatal error:
PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "unflag": SELECT n.nid AS nid, n.uid AS uid FROM {node} n WHERE (nid IN (:db_condition_placeholder_0)) AND (type IN (:db_condition_placeholder_1, :db_condition_placeholder_2)) ; Array ( [:db_condition_placeholder_0] => unflag [:db_condition_placeholder_1] => car [:db_condition_placeholder_2] => article ) in flag_flag_access_multiple() (line 954 of /var/www/html/dev/cambiosale/sites/all/modules/flag/flag.module).
The code it chokes on is this statement:
$result = db_select('node', 'n')
->fields('n', array('nid', 'uid'))
->condition('nid', $content_ids, 'IN')
->condition('type', $flag->types, 'IN')
->execute();
I added code to dump a few variables as JSON, and I get this:
content_ids : {"1":"unflag"}
flag->types: ["car","article"]
The problem as I see it, in in the parameter $content_ids. I think the db_select statement expects it to be an array of integers, but what it gets instead is a sparse array of strings. Likely the intention is to use the array_keys for that parameter. (Note: the single node that I have has the node id 1.)
This seems to be so fundamentally broken... I have no idea why it appears I'm the only one having this problem.
I also made a stack dump (depth 10), see attachment. I took care not to add any lines, so the line numbers are the same as in the original. (The function parameters are dumped in JSON format, using json_encode(), which dumps an object as an associative array. Dumps are truncated, when too long, per parameter.)
Note: I tried 7.x-2.x-dev but it's the same problem, only the line number changes.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | flag.diff | 1.12 KB | bartl |
| stack_dump.txt | 1.47 KB | bartl |
Comments
Comment #1
bartl commentedThe modules involved in the stack trace are Flag and Views, so here's the version info for both:
Flag: 7.x-2.0-beta5
Views: 7.x-3.0-rc1
Comment #2
bartl commentedThe response up till now has been slightly disappointing, so despite being new to Drupal 7 and this module, I decided to dig in myself.
Now according to the docs for access_multiple:
so apparently the format of the data for the parameter $content_ids is actually correct; only the variable name is confusing.
I thought that maybe the problem was because I was using Postgres, and perhaps Mysql acts differently for this method call "condition". But no, the code for both databases is now in common.
So I patched the module by replacing
->condition('nid', $content_ids, 'IN')with
->condition('nid', array_keys($content_ids), 'IN')Unfortunately that appeared to do nothing. Well, actually, it did: the line number of the error message changed. So there was a similar error in another spot... I changed that too, and now everything seems to work.
The attached patch file is intended to be applied from within the "flag" directory with -p0 (or -p1).
Comment #3
wedge commentedThanks for the patch. It fixed this issue for me too.
Comment #4
quicksketchThanks bartl you're a hero for that patch. Sorry I haven't been very active in the Flag queue recently to look into these issues (Flag currently has quite a few issues that have been unearthed since the original D7 porting). Testing out your patch, it looks like you hit the nail on the head here. I've committed your patch to the project, thanks for your help!