#1015. Moved the setting of the session attribute to before the logic is
actually executed.