Skip to content

Fix internal server error when using dynamic client#29

Open
durera wants to merge 1 commit intonolar:mainfrom
durera:dynclientfixes
Open

Fix internal server error when using dynamic client#29
durera wants to merge 1 commit intonolar:mainfrom
durera:dynclientfixes

Conversation

@durera
Copy link
Copy Markdown

@durera durera commented Mar 15, 2026

See the provided test which demonstrates the problem: tests/dynamicclient/test_dynamicclient.py

pytest tests/dynamicclient/test_dynamicclient.py
...                                                                                                        
tests/dynamicclient/test_dynamicclient.py .F                                                                                             [100%]
...
self = <kubernetes.client.rest.RESTClientObject object at 0x75f69cd2a750>, method = 'GET'
url = 'http://127.0.0.1:8080/apis/apps/v1/namespaces/test-namespace/deployments/crud-test-deployment', query_params = []
headers = {'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'OpenAPI-Generator/35.0.0/python'}, body = None      
post_params = {}, _preload_content = False, _request_timeout = None

    def request(self, method, url, query_params=None, headers=None,
                body=None, post_params=None, _preload_content=True,
                _request_timeout=None):
...
        if not 200 <= r.status <= 299:
>           raise ApiException(http_resp=r)
E           kubernetes.client.exceptions.ApiException: (500)
E           Reason: Internal Server Error
E           HTTP response headers: HTTPHeaderDict({'Content-Type': 'text/plain; charset=utf-8', 'Content-Length': '55', 'Date': 'Sun, 15 Mar 2026 22:07:00 GMT', 'Server': 'Python/3.12 aiohttp/3.13.3', 'Connection': 'close'})
E           HTTP response body: b'500 Internal Server Error\n\nServer got itself in trouble'

.venv/lib/python3.12/site-packages/kubernetes/client/rest.py:238: ApiException
...
=================================================== 1 failed, 1 passed, 3 warnings in 9.72s ====================================================

After the change, the expected errors are surfaced, the DynamicClient is happy, and the test passes

pytest tests/dynamicclient/test_dynamicclient.py
...                                                                                                                    
tests/dynamicclient/test_dynamicclient.py ..                                                                                             [100%]
...
======================================================== 2 passed, 5 warnings in 12.30s ========================================================

I contemplated a larger change to relocate the error classes to avoid the circular dependency issue and allow the imports to be defined at the module level, but didn't want to mess with the codebase too much, and this way made the fix a much smaller/safer change to make.

I tried to set up the new test in such a way it could be the basis for more DynamicClient tests in future with re-usable fixtures mirroring how I'm using kmock in my own testing (except instead of directly using DynamicClient I have a whole other layer of indirection ontop because I'm launching ansible playbooks with ansible-runner, and they are using DynamicClient under the covers).

@durera durera requested a review from nolar as a code owner March 15, 2026 23:58
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.

1 participant