Open sxflynn opened 7 months ago
Update: I've identified the line that blocks the Websockets process
config.py
inside the Config()
initializer
# existing line that works, imports from environment variables
self.key = os.getenv(f'{provider_name.upper()}_API_KEY', 'none')
# proposed replacement line, imports from settings instance, currently blocks async websockets
self.key = getattr(settings,f'{provider_name}_api_key','none')
I consulted with the FastAPI docs on settings and environment variables and was unable to make a full request.
await websocket.send_text()
messages were not executing after this line inmain.py
indicating that some kind of side effect of implementing a settings object was causing blocking issues.
Here are the steps I took before discovering this issue:
import
pydantic_settings
and create aBaseSettings
inherited class.Created a settings getter in the global scope of the application
Set up a Depends object as a dependency injection into the main websocket endpoint
Replaced all code related to
os.getenv
withsettings
Somehow, even though I could access the settings variables, like settings.graphql_url, the code was getting blocked as soon as I entered a non-async function, the first being
relevancy_check
.I'd like to implement a proper dependency injection system and pydantic_settings system working, but until then, I will just use
os.getenv