-
Notifications
You must be signed in to change notification settings - Fork 72
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
ApiClient.deserialize should be a function, not a method #128
Comments
Hi @horazont I'm afraid this refactoring won't be easy. Serialize() calls __serialize() which uses some class attributes: https://github.com/tomplus/kubernetes_asyncio/blob/master/kubernetes_asyncio/client/api_client.py#L304 And what's more it's auto-generated by openapi-generator so we have to change the generator first. Other solutions which you can consider:
|
Aha, I see. I scanned the methods twice for references to Yet, this would still work just the same if the methods were As a workaround, we’re currently doing: api_client = ...
try:
# do things
pass
finally:
asyncio.create_task(api_client.close()) :-X Terrible enough, but also shuts up the warning. We don’t want to silence it globally because we had cases of api_client leaks in the past and we want to learn about them. We also don’t want to load both kubernetes_asyncio and kubernetes, and we need kubernetes_asyncio for it being asyncio :). The root issue we’re trying to solve is that we need to write a function which inspects V1PodSpec and it needs to deal with both the raw JSON representation and the V1PodSpec instances (depending on where the data comes from). As .as_dict() on the V1PodSpec does not recreate the JSON representation correctly (for example, volume_mounts vs. volumeMounts), we went the other way. If there’s a nicer solution to this, that’d also be appreciated. |
Changing generator is not an easy, especially if you want to be backward compatible. Do you consider using I think, we can add a simple function to module "utils" which takes object as input and returns dict using this map. What do you think? |
That would effectively be a re-implementation of what |
As far as I can tell, it does not use any attributes of the ApiClient.
The advantage of having it as function would be to have it available without needing to construct an ApiClient (as the Watch currently does). Normally, constructing an ApiClient would not be a problem. However, if one is in a non-async context, one cannot properly clean the client up and that will cause a warning ("asyncio: ERROR: Unclosed client session").
I would be happy to provide a PR if you agree.
The text was updated successfully, but these errors were encountered: