microsoft / kiota-python

Abstractions library for Kiota generated Python clients
https://aka.ms/kiota/docs
MIT License
16 stars 11 forks source link

base_url property in request_adapter.http_client is not used by HttpXRequestAdapter #374

Open jimisola opened 1 month ago

jimisola commented 1 month ago

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

Python

Describe the bug

AsyncClient.base_url is not used by HttpxRequestAdapter as expected.

      http_asyncclient: AsyncClient = AsyncClient(
            base_url=self.stimulator_config.server.base_url,  # BUG base_url not used, file issue with kiota
            ),
            headers=headers,
        )
        request_adapter: HttpxRequestAdapter = HttpxRequestAdapter(
            authentication_provider=auth_provider,
            http_client=http_asyncclient,
            # base_url=app_config.server.base_url, # base_url must be set here         )
        client: ApiClient = ApiClient(request_adapter=request_adapter)

Expected behavior

HttpxRequestAdapter uses HttpxRequestAdapter.http_client.base_url

How to reproduce

See above.

Open API description file

No response

Kiota Version

1.18.0

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

Set base_url in

Configuration

Debug output

Click to expand log ``` ```

Other information

We are using microsoft-kiota-http==1.3.3 (HttpxRequestAdapter). I updated to 1.3.4 but the constructor of HttpxRequestAdapter has not changed from what I can see.

See: https://github.com/microsoft/kiota-http-python/blob/main/kiota_http/httpx_request_adapter.py#L90

baywet commented 1 month ago

Hi @jimisola Thank you for using kiota and for reaching out.

You are correct, in dotnet, if a base url is set on the underlying HTTP client, it's used by the request adapter. https://github.com/microsoft/kiota-dotnet/blob/650812d9b598f192e6e55424e327d2bcee49c99a/src/http/httpClient/HttpClientRequestAdapter.cs#L52

This is something that could be fixed by adding a couple of conditions here https://github.com/microsoft/kiota-python/blob/43bff74140a544183a81d4975e936974c2ba8a45/packages/http/httpx/kiota_http/httpx_request_adapter.py#L90

(explicitly passed base URL should take precedence over the one from the underlying http client)

By reading the base url property https://github.com/encode/httpx/blob/1bf1fc0ea8417c8e539914aeafdb48f15591ba75/httpx/_client.py#L268

Is this something you'd like to submit a pull request for provided some guidance?

jimisola commented 1 month ago

Hi @baywet

Thanks for confirming the issue.

The fix is normally the easy thing whereas getting to know the project, i.e. how to build, test, do code formatting etc is usually what takes time.

I can have a look at it but I don't know when due to deadlines at work and some involvement in some other open source projects.