Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernelci.cli: allow multiple values for .split_attributes() #2195

Merged
merged 1 commit into from
Nov 23, 2023

Conversation

gctucker
Copy link
Contributor

@gctucker gctucker commented Nov 17, 2023

Allow the same attribute to be provided several times in .split_attributes(). This is useful when looking for database entries that match one of a set of values e.g. name=foo?name=bar to find entries named 'foo' or 'bar'.

Update unit tests accordingly with an additional one to test the generated request URL with multiple values for the same parameter.

@nuclearcat
Copy link
Member

But is it implemented in API side? I think this way we are entering a bit uncharted territory of boolean logic, right now by default we have AND as i understand, but in this case it becomes OR?
for example we might need: foo > 100 AND foo < 200 (especially in searching date range for tests results)

@gctucker
Copy link
Contributor Author

No it's not implemented on the API side yet.

@gctucker gctucker force-pushed the split-attr-multiple branch 2 times, most recently from 83997da to 22682da Compare November 20, 2023 08:03
Allow the same attribute to be provided several times in
.split_attributes().  This is useful when looking for database entries
that match one of a set of values e.g. name=foo?name=bar to find
entries named 'foo' or 'bar'.

Update unit tests accordingly with an additional one to test the
generated request URL with multiple values for the same parameter.

Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
@JenySadadia
Copy link
Collaborator

Tested locally:

$ ./kci user find username=bob username=admin1
[]

This doesn't return the user with the name bob as I don't have any user named admin1. I think it looks only for the last value it receives. I guess this needs a fix on the API side.

@JenySadadia
Copy link
Collaborator

I thought we were trying to fix the issue I mentioned in #2184 (comment). When multiple values for --group are received, it should combine all the values into a list/tuple and send it to API. Just like what Click does with options like @click.option('--group', multiple=True).

@gctucker
Copy link
Contributor Author

Yes, I'm not sure if the API can handle things properly. But at least the logic here on the client side is working to produce the right URL.

@JenySadadia
Copy link
Collaborator

This works when I send multiple groups attributes in a request:

$ ./kci user update --username=test1 username=test groups=kernelci groups=admin
fields {'username': 'test', 'groups': ['kernelci', 'admin']}

When I send just one groups, it is not converting it to a list. API returns an error as it expects a list for groups attribute:

$ ./kci user update --username=test groups=kernelci
fields {'groups': 'kernelci'}
requests.exceptions.HTTPError: 422 Client Error: Unprocessable Entity for url: http://172.17.0.1:8001/latest/user/652cfd850a9d4984577826c8

I guess split_attributes is working as expected and groups is a special case and needs to be handled separately.

Copy link
Collaborator

@JenySadadia JenySadadia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handling groups can be a follow-up PR. Merging this now.

@JenySadadia JenySadadia added this pull request to the merge queue Nov 23, 2023
Merged via the queue into kernelci:main with commit a454245 Nov 23, 2023
4 checks passed
@gctucker
Copy link
Contributor Author

Ah, yes the whole group handling thing will need to be revisited. That can be done as part of the work to add the kci user group commands I guess.

@gctucker gctucker deleted the split-attr-multiple branch November 23, 2023 10:18
@gctucker gctucker mentioned this pull request Dec 15, 2023
40 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants