Closed ponty33 closed 1 year ago
I will answer 2 first, yes, it just doesn't work. There are something about ABC behavior that I don't under stand, but I couldn't make it work when writing test for it
If 2 is not doable, the only work around I can think of is enter it in the arg
If you use the same constant such as API_VERSION='2023-04'
in the code you can ensure it's always using the same version in the code. I know it's not pretty, but since simply assign doesn't work then I don't know what else I can do.
I don't see the problem here:
from abc import ABC, abstractmethod
from typing import ClassVar, Optional
from pydantic import BaseModel
class Token(ABC, BaseModel):
store_name: str
api_version: ClassVar[Optional[str]] = None
class OfflineTokenABC(Token, ABC):
@abstractmethod
def version(self):
pass
class MyOfflineTokenABC(OfflineTokenABC):
api_version: ClassVar[Optional[str]] = '2023-04'
def version(self):
print(self.api_version)
offline = MyOfflineTokenABC(store_name='potato')
print(offline.api_version)
offline.version()
MyOfflineTokenABC.api_version = '2024-04'
print(offline.api_version)
print(Token.api_version)
Output as expected:
2023-04
2023-04
2024-04
None
So two ways of setting the api_version. Maybe I'm not testing your problem though ...
I found where I did wrong...
When I wrote the test, I make the load
function returning another class that doesn't have API version :sweat:
No wonder the version is nowhere to be found :disappointed:
api_version
inToken
, I couldn't found a way to override the field valueapi_version
be input inexecute_rest
andexecute_gql
, since we construct full url inside the function/admin
which the oldest supported version will be usedclose #173