Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

220
Vistas
How to set order of Middlewares in FastAPI?

So I am using this open-source available MDW: https://github.com/snok/asgi-correlation-id which essentially just generates and adds a unique Correlation ID for incoming requests in FastAPI app.

However, I have created another custom middleware for my app, this way:

@app.middleware("http")
async def some_custom_mdw_function(request: Request, call_next):
    # some operation  I do here
    # which also requires me fetching the 
    # correlation_id created via the asgi-correlation-id
    # I have code line over here like:

    asgi_corr_id = correlation_id.get() # a function imported from asgi-correlation-id library

This however gives me an error sometimes, since apparently, those times, this some_custom_mdw_function MDW is called before the asgi-correlation-id MDW, and hence the correlation ID is not found.

How do I ensure that asgi-correlation-id MDW is called always before some_custom_mdw_function MDW? Is there a way to set the order of executions for MDW in FastAPI?

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda