Drupal 7.0-RC2
References 7.x-2.x-dev (2010-Dec-08)
I created content type with User Reference field 'Supervisor' and set up filter by 'role' and 'active' state of the account. Used 'autocomplete' widget to select users.
When I trying to create a node, Drupal crashes with following error:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'uid' in where clause is ambiguous: SELECT u.uid AS uid, u.name AS name, u.status AS status, r.rid AS rid
FROM {users} u
INNER JOIN {users_roles} r ON u.uid = r.uid
WHERE (u.status IN (:db_condition_placeholder_0, :db_condition_placeholder_1)) AND (r.rid IN (:db_condition_placeholder_2, :db_condition_placeholder_3, :db_condition_placeholder_4, :db_condition_placeholder_5, :db_condition_placeholder_6, :db_condition_placeholder_7, :db_condition_placeholder_8)) AND (uid IN (:db_condition_placeholder_9)) ORDER BY name ASC; Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => 0 [:db_condition_placeholder_2] => 5 [:db_condition_placeholder_3] => 0 [:db_condition_placeholder_4] => 0 [:db_condition_placeholder_5] => 0 [:db_condition_placeholder_6] => 0 [:db_condition_placeholder_7] => 0 [:db_condition_placeholder_8] => 0 [:db_condition_placeholder_9] => 2 ) in _user_reference_potential_references_standard() (line 491 of C:\wamp\www\drupal-7.0\sites\all\modules\references\user_reference\user_reference.module).
Any ideas? If you need additional info, let me know.
Comments
Comment #1
fgmCollision happens between the uid columns in users and users_roles.
Comment #2
fgmAliasing that field seems to fix the issue.
Comment #3
andypostUser autocomplete is totally broken now.
Patch fixes following:
- Fixes UID using more conditional logic
- Fixes arguments for filters: array_keys(array_filter($settings)) leaves only checked values for queries
- Used format_username() to allow modules a-la realname to alter user names?
Last one probably useless for this function so maybe it's different issue
Questions raised:
- Defaults for filters:
-- should we display autocomplete widget if nothing is checked in filters?
-- should we display Anonymous user? Currently using "%" as autocomplete value we could get Anonym into list (last patch fixes this with continue)
Comment #4
ogi commentedsubscribe
Comment #5
XiaN Vizjereij commentedSubscribing and escalating to critical, because with this bug the whole user reference field is not working at all. I will apply the patch later today and report back :)
Comment #6
fgmXiaN, since you are testing, can you check both patches separately ? andypost's is more significant, but both should work.
This does not crash sites, so downgrading from critical.
Comment #7
XiaN Vizjereij commentedI will, however i won't have the time to test them on my site until next Thursday, so it might be faster if you test them :)
Comment #8
mokitger commentedsubscribe
Comment #9
achinn commentedsubscribe
Comment #10
rych commentedThe patch in #3 works for me.
Thank you andypost!
Drupal 7.0
References 7.x-2.x-dev, date: 2011-jan-15
Comment #11
fgm#2: references_1004212.patch queued for re-testing.
Comment #12
yched commentedTested manually, patch looks good to me.
Comment #13
yched commentedSide note: #1038102: user ref settings : 'blocked' checkbox does not save
Comment #14
yched commented@fgm : if you don't commit this, I will ;-)
Comment #15
fgmThe patch in #3 is indeed mostly good. Some nitpicking, and a more basic question:
'=' is the default on condition(), so not needed
This is probably for another issue, but do we really want to forbid user_referencing anonymous ?
Powered by Dreditor.
In addition, it would be good to have a simpletest that fails prior to patch and succeeds with it, to prevent regressions later on.
Comment #16
fgmForgot to set status.
Also, if nothing is set in filters, it should mean no filters are applied, as elsewhere in Drupal, so the query should return all users, just as if all filters had been checked individually.
Comment #17
yched commented- "if nothing is set in filters, it should mean no filters are applied"
I probably agree - although that's not how current D6 fields work, and not how noderef's 'referenceable node types' checkboxes work either.
But I guess we can assume that there are little chances of actual D6 fields out there with empty referenceable types or roles, since they would be basically useless - aside from noderef fields defined using a view, but for those we overlook the 'referenceable types' setting altogether anyway.
So yes, I think that change would be fine, and a usability win (catch all, including node types / user roles added subsequently), but that's probably outside the scope of this 'unbreak userref' issue, since this would imply some noderef changes as well for consistency.
- "do we really want to forbid user_referencing anonymous ?"
Hm. Different question indeed. For now let's say we do. Currently uid 0 is considered an empty value (see user_reference_field_is_empty()).
However, this uid != 0 check should probably be included in the query rather than in the loop over the result set.
Comment #18
yched commentedcreated #1047534: make "no referenceable types" = "no filter" (all types)
Comment #19
tuhin-1 commented#3: 1004212-userref-dbtng.patch queued for re-testing.
Comment #20
dealancer commentedThank you for the patch #3. It is working perfect thanks for Real Name support!
Comment #21
bjlewis2 commentedPatch in #3 works great!
Comment #22
andypostUsing '=' brings more readability to code
This place need special processing because UID=0 has no name. So if we really need Anonymous we should care about it's display
I think we need to commit this patch and fix UID0 case in different issue. I have no ideas about writing a tests for this code because it has no UI...
Powered by Dreditor.
Comment #23
yched commentedI usually advocate leaving defaults out, but I agree that in the specific code sequence and in the middle of the other "conditional conditions", leaving the explicit '=' operator is clearer.
Added a 'uid <> 0' condition to the query (rather than checking on the PHP side), and some minor code reordering, and committed the attached patch.
Interdiff with #3 attached.
Comment #24
andypostGreat step to module release!
Agreed that Anonymous user usage should be discussed but I see not real examples of usage...
Also module planing to support displaying UID0 so it needs own implementation of user_load to assign a name to UID0
Comment #25
goldlilys commentedThanks #3 worked for me too.
Comment #27
chunglk commented