-
Notifications
You must be signed in to change notification settings - Fork 107
Description
Hi,
My Python Azure Function App uses the Pydantic Settings library (https://github.com/pydantic/pydantic-settings). We have a config
module that has a Settings class that looks like this:
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file='.env', extra='ignore')
SOME_CONFIG_SETTING: str
settings = Settings()
We import the settings
variable in our function_app.py
file:
from config import settings
This works fine locally.
The problem is that when we deploy this (Flex Consumption plan), it sometimes works, and sometimes we get back a 404 from the function app endpoint.
curl -i https://********.swedencentral-01.azurewebsites.net/api/test
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Date: Fri, 12 Sep 2025 15:40:15 GMT
Server: Kestrel
Transfer-Encoding: chunked
v6 - This is a terrible secret
... and immediately after:
curl -i https://********.swedencentral-01.azurewebsites.net/api/test
HTTP/1.1 404 Not Found
Content-Length: 0
Date: Fri, 12 Sep 2025 15:40:16 GMT
Server: Kestrel
Request-Context: appId=cid-v1:ecdd68ef-42b2-48f5-8e23-4abb541b8212
If instead I remove the last line in the config module above, and instead create the settings
variable directly in the endpoint function, it works, no 404s.
Any ideas why this might be so? We normally import our config initialisation at the top in function_app.py
so that it only happens once per Python worker startup. We don't want to have to put it in every function (our real one reads from an Azure Key Vault)
I've created a minimal example that shows the issue here: https://github.com/derekmcloughlin/azure-functions-pydantic-settings-test
Python 3.12.10
V2
Core Tools 4.2.2
Function Runtime Version: 4.1041.200.25360
Manual deployment from VS Code