Sage-Bionetworks / sage-monorepo

Where OpenChallenges, Schematic, and other Sage open source apps are built
https://sage-bionetworks.github.io/sage-monorepo/
Apache License 2.0
23 stars 12 forks source link

[Bug] OC API client for Python ignore values defined in `ChallengeSearchQuery` when listing challenges #2296

Open tschaffter opened 11 months ago

tschaffter commented 11 months ago

Is there an existing issue for this?

What product(s) are you seeing the problem on?

OpenChallenges

Current behavior

I'm trying to get all the challenges. The query shown below shows that all the challenges can be listed on a single page.

https://openchallenges.io/api/v1/challenges?sort=created&pageSize=1000

image

The following code fails to do the same in Python:

# Enter a context with an instance of the API client
challenges = []
with openchallenges_client.ApiClient(configuration) as api_client:
    api_instance = challenge_api.ChallengeApi(api_client)

    query = openchallenges_client.ChallengeSearchQuery(page_number=1, page_size=1000)
    pprint(query)

    try:
        # Get the first page of the list of challenges
        page = api_instance.list_challenges(query)
        pprint(page.total_pages)
        challenges.extend(page.challenges)
    except openchallenges_client.ApiException as e:
        print("Exception when calling ChallengeApi->list_challenges: %s\n" % e)

The page size return is always 3 and the number of results per page is 100, independently of the value of query. 100 is the default page size. However, I updated the API description, regenerated the API client and reinstalled it. The client code shows that the change is effective, but my script still fetch 100 challenges per page.

Expected behavior

No response

Anything else?

No response

Commit ID

No response

Are you developing inside the dev container?

Code of Conduct

tschaffter commented 11 months ago

The issue is that the auto-generated API client does not seem to support object as query params. Consider the following code from challenge_api.py:

        # process the query parameters
        _query_params = []
        _query_params.append(('pageSize', 1000))
        # if _params.get('challenge_search_query') is not None:  # noqa: E501
        #     _query_params.append(('challengeSearchQuery', _params['challenge_search_query']))

This adds a query param named challengeSearchQuery, which is not supported the auto-generated client.

This is not the first time that an issue arise because we use an object, which was decided because this enables to group the params in one schema. While this works fine with code generated for the Java server, Angular and Axios cients, there was also an issue in R. The issue was reported to the official repo of OpenAPI Generator. Was the fix supposed to fix exactly this issue for R?

Note It is also more developer friendly to have the query params grouped into a single object.

The easiest path forward would be to update the API description to no longer rely on objects for query params. This change should have minimal impact on existing implementation. The change should be tested on a single endpoint first.

tschaffter commented 11 months ago

I have "hacked" the API client locally so that I could fetch all the challenges on one page:

        # process the query parameters
        _query_params = []
        _query_params.append(('pageSize', 1000))
        # if _params.get('challenge_search_query') is not None:  # noqa: E501
        #     _query_params.append(('challengeSearchQuery', _params['challenge_search_query']))
tschaffter commented 10 months ago

Update 2023-12-04

I didn't have time to address this in November but am now aiming to fix this bug this sprint. I will also devise a plan to release the Python client in January, which will be one of the highlight of OC. E.g. we should provide a Python notebook that shows how to use the API client, e.g. to get a list of challenges or the papers (DOI) of the challenges an org has contributed to.

tschaffter commented 10 months ago

Added to Sprint 23.12

tschaffter commented 7 months ago

Added to Backlog