88import urllib .parse
99import warnings
1010from contextlib import asynccontextmanager
11- from functools import cache , partial
11+ from functools import partial
1212from pathlib import Path
1313from typing import Any , Optional
1414
@@ -288,7 +288,7 @@ async def unhandled_exception_handler(
288288 serialization_registry ,
289289 deserialization_registry ,
290290 validation_registry ,
291- authenticators ,
291+ server_settings . authenticators ,
292292 )
293293 app .include_router (router , prefix = "/api/v1" )
294294
@@ -299,7 +299,7 @@ async def unhandled_exception_handler(
299299 for custom_router in getattr (tree , "include_routers" , []):
300300 app .include_router (custom_router , prefix = "/api/v1" )
301301
302- if authenticators :
302+ if server_settings . authenticators :
303303 # Delay this imports to avoid delaying startup with the SQL and cryptography
304304 # imports if they are not needed.
305305 from .authentication import (
@@ -310,7 +310,7 @@ async def unhandled_exception_handler(
310310 )
311311
312312 # For the OpenAPI schema, inject a OAuth2PasswordBearer URL.
313- first_provider = authentication [ "providers" ][ 0 ][ "provider" ]
313+ first_provider = list ( server_settings . authenticators )[ 0 ]
314314 oauth2_scheme .model .flows .password .tokenUrl = (
315315 f"/api/v1/auth/provider/{ first_provider } /token"
316316 )
@@ -337,47 +337,6 @@ async def unhandled_exception_handler(
337337 else :
338338 app .state .authenticated = False
339339
340- @cache
341- def override_get_settings ():
342- settings = get_settings ()
343- for item in [
344- "allow_anonymous_access" ,
345- "secret_keys" ,
346- "single_user_api_key" ,
347- "access_token_max_age" ,
348- "refresh_token_max_age" ,
349- "session_max_age" ,
350- ]:
351- if authentication .get (item ) is not None :
352- setattr (settings , item , authentication [item ])
353- for item in [
354- "allow_origins" ,
355- "response_bytesize_limit" ,
356- "reject_undeclared_specs" ,
357- "expose_raw_assets" ,
358- ]:
359- if server_settings .get (item ) is not None :
360- setattr (settings , item , server_settings [item ])
361- database = server_settings .get ("database" , {})
362- if uri := database .get ("uri" ):
363- settings .database_settings .uri = uri
364- if pool_size := database .get ("pool_size" ):
365- settings .database_settings .pool_size = pool_size
366- if pool_pre_ping := database .get ("pool_pre_ping" ):
367- settings .database_settings .pool_pre_ping = pool_pre_ping
368- if max_overflow := database .get ("max_overflow" ):
369- settings .database_settings .max_overflow = max_overflow
370- if init_if_not_exists := database .get ("init_if_not_exists" ):
371- settings .database_init_if_not_exists = init_if_not_exists
372- if authentication .get ("providers" ):
373- # If we support authentication providers, we need a database, so if one is
374- # not set, use a SQLite database in memory. Horizontally scaled deployments
375- # must specify a persistent database.
376- settings .database_settings .uri = (
377- settings .database_settings .uri or "sqlite://"
378- )
379- return settings
380-
381340 async def startup_event ():
382341 from .. import __version__
383342
@@ -656,7 +615,6 @@ async def set_cookies(request: Request, call_next):
656615 return response
657616
658617 app .openapi = partial (custom_openapi , app )
659- app .dependency_overrides [get_settings ] = override_get_settings
660618
661619 @app .middleware ("http" )
662620 async def capture_metrics (request : Request , call_next ):
0 commit comments