It is always layered.  You are correct that we always want to use the course_id defined here, because we can't accurately detect the course_id using the URL parsing middleware since the URL will always be /event and the "page" variable contains the *actual* URL we care about.

That said, I don't want to actually overwrite the middleware-provided context, I simply want to layer this information on top of it so that when you leave the context manager, you are still left with a single context on the stack, which can (and will) get cleaned up by the middleware.