Field required [type=missing, input_value, ...... input_type=dict]

319 views Asked by At

I have a settings model that is supposed to be setting up a CosmosDB connection. This was working in a previous version of Pydantic. I switched to 2.6 and I keep getting the following error:

| connection_string
|   Field required [type=missing, input_value={'app_insights_connection...14d7561723120bbbf2e9ed'}, input_type=dict]
|     For further information visit https://errors.pydantic.dev/2.6/v/missing
| database_name
|   Field required [type=missing, input_value={'app_insights_connection...14d7561723120bbbf2e9ed'}, input_type=dict]
|     For further information visit https://errors.pydantic.dev/2.6/v/missing

My code looks like this:

class CosmosSettings(BaseSettings):
    connection_string: int
    database_name: dict

    class Config:
        extra = 'allow'
        env_file = '.env'
        env_file_encoding = 'utf-8'
        fields = {
            'connection_string': {'env': 'COSMOS_CONNECTION_STRING'},
            'database_name': {'env': 'COSMOS_DATABASE_NAME'},
        }


settings = CosmosSettings()


class BaseDB:
    def __init__(self, container: str):
        self.client = CosmosClient.from_connection_string(settings.connection_string)
        self.database = self.client.get_database_client(settings.database_name)
        self.container = self.database.get_container_client(container)

I have a couple other settings file like this that sets up connections for REDIS and PostgreSQL. This is the only one that keeps complaining about a missing input type even though it is clearly provided.

I am new to Pydantic, however I have spent over a day searching through the documentation and other StackOverflow questions, and I cannot figure out what is wrong.

0

There are 0 answers