Skip to content
Discussion options

You must be logged in to vote

Yes, in your case the result of get_context will be cached and it will be the same object during one endpoint call.
Doc: https://fastapi.tiangolo.com/tutorial/dependencies/sub-dependencies/#using-the-same-dependency-multiple-times

To test that you can add assert context == batch_processor.context to your endpoint code:

# An endpoint that depends on both Context and BatchProcessor
@app.get("/my_endpoint")
async def my_endpoint(context: Context = Depends(get_context), 
                      batch_processor: BatchProcessor = Depends(get_batch_processor)):
    # Here, you can use both context and batch_processor as needed

    assert context == batch_processor.context

    return {"message": …

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@mrdeveloperdude
Comment options

@YuriiMotov
Comment options

@YuriiMotov
Comment options

Answer selected by mrdeveloperdude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
2 participants