This is a late answer, but it has been linked as a source of confusion for some Pyramid users.
The accepted answer here is not the actual reason that unauthenticated_userid used for request.user . This has nothing to do with performance.
The reason it uses unauthenticated_userid is because it makes it easy to reuse the authentication policy between applications with the required smaller changes. Your application needs a “source of truth” in order to allow the user to be considered authenticated, and, as a rule, the internal logic of the policy is not enough to make this determination. The correct cookie is good, but you usually want to check it with the backend before trusting it. Great, so where do we put this logic? Well, unauthenticated_userid does not make sense because it is a reusable piece of policy that specifically focuses on parsing request headers. You can put it in authenticated_userid , but this method is not the one you usually need in your application. Usually you use request.user in your applications (rarely, you probably take care of request.authenticated_userid directly), and finally request.user is a superset of functionality - it provides an entire user object, not just an identifier. It would be foolish to check the identifier without checking the entire object in most cases. We can have only one "source of truth", and therefore the recipe declares it to request.user . The group sensor (and therefore authenticated_userid ) can now depend on request.user and hope that what it returns from there has been correctly verified using the backend. Also, request.user already confirmed, and therefore speeds up subsequent calls to request.authenticated_userid .
source share