Visitar URL original
Arrays are not sent correctly due to not using [] after variable name · Issue #1419 · python-gitlab/python-gitlab · GitHub
Skip to content

Arrays are not sent correctly due to not using [] after variable name #1419

Description

@JohnVillalovos

Arrays are not sent correctly due to not using [] after variable name

GitLab's API documentation: https://docs.gitlab.com/ee/api/#array

array types

import_sources is a parameter of type array:

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
-d "import_sources[]=github" \
-d "import_sources[]=bitbucket" \
"https://gitlab.example.com/api/v4/some_endpoint"

So when we send array values we most append [] to the array's variable name.

This has caused issues like:

Activity

  1. nejch commented on Apr 27, 2021

    @nejch
    Member

    Thanks for that @JohnVillalovos! I thought it might be something to do with arrays.

    So this means we might have to manually maintain a lot of custom _types fields 🤔 I'm just not 100% sure that really all GitLab API endpoints take form-encoded arrays in addition to comma-delimited strings. See this upstream from a while ago (probably outdated now) https://gitlab.com/gitlab-org/gitlab-foss/-/issues/48007. I think it's time I added some parametrized integration tests for this.

  2. JohnVillalovos commented on Apr 27, 2021

    @JohnVillalovos
    MemberAuthor

    @nejch

    On the good news, it seems like an array can be sent as a comma-delimited string. (https://gitlab.com/gitlab-org/gitlab/-/blob/5ecf69de438d221ed25f5f86756721f5f7b7b389/lib/api/validations/types/comma_separated_to_array.rb#L13)

    This is probably the easiest way to make it work with using the types.ListAtribute. So then iids=[1,2,3] will become iids=1,2,3 in the HTTP request.

    More complicated would be to take a value like: iids=[1, 2, 3] and then convert that into iids[]=1&iids[]=2&iids[]=3 in the HTTP request.

    Thoughts?

  3. nejch commented on Apr 27, 2021

    @nejch
    Member

    Agreed, if gitlab handles it then this should do for now. I also just did a quick grep and seems like all GET params that are arrays get massaged with the above from strings :) If it's a problem later we can convert to an array with urlencode.

    Edit: On second thought, there are also cases where this probably won't help, see e.g. https://gitlab.com/gitlab-org/gitlab/-/blob/5889dadb55c8d7b6a4c6a378914769eea16717d1/lib/api/jobs.rb#L16-29. So #806 won't be fixed by this.

  4. locked as resolved and limited conversation to collaborators on May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions