File: upstox_client/configuration.py Lines: 25-40
The Configuration class is generated by Swagger Codegen and uses a custom metaclass called TypeWithDefault. This metaclass is designed to cache the first instantiated object and return a shallow copy of it on all subsequent instantiations.
# Lines 30-33 in configuration.py
def __call__(cls, *args, **kwargs):
if cls._default is None:
cls._default = type.__call__(cls, *args, **kwargs)
return copy.copy(cls._default)
Why this is a bug: Because of this metaclass, the init(self, sandbox=False) constructor is only ever evaluated once per Python process. If a developer initializes the Live client first (config = Configuration()), the default object is cached with the Live endpoints (https://api.upstox.com). If the developer later tries to initialize a Sandbox client (config = Configuration(sandbox=True)), the init method is completely bypassed! The metaclass just returns a shallow copy of the Live configuration, completely ignoring the sandbox=True argument.
Impact: Developers building hybrid applications cannot switch between Sandbox and Live modes dynamically. They are forced to manually override the internal properties (config.host and config.order_host) every time they instantiate a client.
File: upstox_client/configuration.py Lines: 25-40
The Configuration class is generated by Swagger Codegen and uses a custom metaclass called TypeWithDefault. This metaclass is designed to cache the first instantiated object and return a shallow copy of it on all subsequent instantiations.
Why this is a bug: Because of this metaclass, the init(self, sandbox=False) constructor is only ever evaluated once per Python process. If a developer initializes the Live client first (config = Configuration()), the default object is cached with the Live endpoints (https://api.upstox.com). If the developer later tries to initialize a Sandbox client (config = Configuration(sandbox=True)), the init method is completely bypassed! The metaclass just returns a shallow copy of the Live configuration, completely ignoring the sandbox=True argument.
Impact: Developers building hybrid applications cannot switch between Sandbox and Live modes dynamically. They are forced to manually override the internal properties (config.host and config.order_host) every time they instantiate a client.