Page MenuHomePhabricator

Query multiple usernames not working with 'Query Account' api
Closed, ResolvedPublic

Description

I tried out the 'Query Account' API to get the account IDs of the users by inputting the usernames. A simple example is:

https://gerrit.wikimedia.org/r/accounts/?q=rammanojpotla&q=some_random_username

The above query only returns the accountID user with username: "some_random_user" but ignores the first query. I performed the same request with the following API

https://gerrit.wikimedia.org/r/changes/?q=owner:rammanojpotla&q=owner:some_random_user

The above query returns the results regarding the two users. But This is not the case with the initial query!!

url to the doc: https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#query-account

Event Timeline

Aklapper changed the task status from Open to Stalled.EditedJun 29 2019, 3:13 PM

@Rammanojpotla If https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#query-account somewhere mentions that you can use the accounts backend to query the same value twice in the same request, then please point out the exact sentence that you found.

Are you telling about _more_accounts: true ??

It means that if a user creates two different accounts with the same email, it is possible to get the accountIDs of both the accounts. But if there are two different users with usernames:

  1. UserA
  2. UserB

If I request the API, by https://gerrit.wikimedia.org/r/accounts/?q=UserA&q=UserB. I guess it has to return the accountIDs of both the accounts (as I am performing two different queries using q tag). But it actually returns the AccountID of UserB.

For example, https://gerrit.wikimedia.org/r/accounts/?q=rammanojpotla returns two accountIDs as I have two different accounts. But If I perform a query something like https://gerrit.wikimedia.org/r/accounts/?q=rammanojpotla&q=gopavasanth. It returns the accountID of the user: GopaVasanth only(the last user in the query). It is missing the information about the first user (i.e rammanojpotla).

But if you perform the same with the url: https://gerrit.wikimedia.org/r/changes/?q=owner:rammanoj&q=owner:gopavasanth&o=DETAILED_ACCOUNTS. It returns the commits of both the users.

Are you telling about _more_accounts: true ??

I don't tell about anything - I am asking you. The example at https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html#query-account which you linked to includes one (1) parameter value: q=name:John+email:example.com.
Not two (2) values like in your example in this task: q=rammanojpotla&q=some_random_username

Hence I ask you why you think that your example would be supported by the Gerrit software, and ask you to point to documentation which shows that your syntax is supported.

Yeah, It does not show an example, But I while I was reading about the API. I came to know that q is actually the query. When it worked with(https://gerrit.wikimedia.org/r/changes/?q=owner:rammanoj&q=owner:gopavasanth&o=DETAILED_ACCOUNTS). I thought it would also work for the above API.

Aklapper changed the task status from Stalled to Open.Jul 8 2019, 1:08 PM
hashar claimed this task.
hashar subscribed.

The q parameter is the query string and it is not meant to be indicated more than once. Thus when you send:

qrammanoj
qgovasanth

Only the last is used. Gerrit will then attempt to match govasanth against the usernames or emails and return whatever account matches.

The syntax for the accounts API query is at https://gerrit-review.googlesource.com/Documentation/user-search-accounts.html#_search_operators, they indicate:

As more operators are added to the same query string, they further restrict the returned results.

So if you went to send a query such as: q=username:rammanjob+username:govasanth, it will try to find an account whose username matches BOTH rammanjob and govasanth.

Instead one has to send two queries, preferably with the username: search predicate to avoid matching emails.

Not much to be fixed here, I am closing the task.