Skip to content

Configuration Class behaves as a Singleton, ignoring subsequent __init__ arguments #155

Description

@Anshu666666

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions