Access context from another middleware
HarrySky opened this issue ยท 2 comments
Hi, thanks for this great middleware!
I was trying to access context from another middleware and was getting a lot of RuntimeError
s saying I was not in request-response cycle.
Problem is solved, I am leaving this issue in case somebody else have this "access context in another middleware" use-case and is getting RuntimeError
s. You should add RawContextMiddleware
last (see: encode/starlette#479):
app = Starlette() # or FastAPI()
# Add your middleware that uses context here...
app.add_middleware(RawContextMiddleware)
It would be great if you could add a warning about this in docs' examples, but I don't insist as it is actually more of a Starlette problem
Hey, thanks!
Proper order of middlewares is important in all web apps. It's not a Starlette problem, it's just what it is.
I don't like hanging tickets. I was sure I mentioned the proper order of middlewares in the docs but can't find it anywhere so I'll do that.
Thanks for pointing that out!
I added this section in the docs.
https://starlette-context.readthedocs.io/en/latest/errors.html
Cheers!