Skip to content

SDK import fails when .env file contains non-MarketData variables #14

@MarketDataApp

Description

@MarketDataApp

Description

The SDK cannot be imported in applications that have other environment variables defined in their .env file. This prevents the SDK from being used in multi-service applications.

Root Cause

The MarketDataSettings class in settings.py uses pydantic-settings which defaults to extra='forbid' when parsing .env files. This causes a ValidationError when ANY environment variable exists in .env that isn't explicitly defined in the model.

Reproduction

  1. Create a .env file with any variable not defined by MarketData:

    MY_APP_KEY=123
    REDIS_HOST=localhost
    
  2. Try to import the SDK:

    from marketdata.client import Client
  3. Import fails immediately:

    pydantic_core._pydantic_core.ValidationError: 2 validation errors for MarketDataSettings
    my_app_key
      Extra inputs are not permitted [type=extra_forbidden, input_value='123', input_type=str]
    redis_host
      Extra inputs are not permitted [type=extra_forbidden, input_value='localhost', input_type=str]
    

Impact

  • SDK is unusable in any application with other environment variables in .env
  • Prevents integration with frameworks like Django, Flask, FastAPI that use their own env vars
  • Breaks in containerized environments where multiple services share .env files
  • Error occurs at module load time, before any client code can run

Suggested Fix

Add extra='ignore' to the model configuration in settings.py:

model_config = ConfigDict(
    env_file=".env",
    env_file_encoding="utf-8",
    extra='ignore'  # Allow other env vars to exist
)

Environment

  • SDK version: v1.1.0
  • Python: 3.13
  • pydantic-settings: 2.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions