From 51ceb160e15191d003260512167357f451370280 Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:16:05 +0800 Subject: [PATCH] Only add errors to the session if they exist --- src/masonite/middleware/route/SessionMiddleware.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/masonite/middleware/route/SessionMiddleware.py b/src/masonite/middleware/route/SessionMiddleware.py index 5a1103bf..bf0f4e2b 100644 --- a/src/masonite/middleware/route/SessionMiddleware.py +++ b/src/masonite/middleware/route/SessionMiddleware.py @@ -17,11 +17,12 @@ def before(self, request, response): request.app.make("request").session = Session # TODO: Remove in Masonite 5 - bag = MessageBag(Session.get("errors") or {}) - request.app.make("view").share({"errors": bag.helper}) + errors = Session.get("errors") or {} + request.app.make("view").share({"errors": MessageBag(errors).helper}) # errors are stored in session flash so 'getting' them actually clears them - # so re-add them to the session as a MessageBag - Session.flash('errors', bag) + # if any then re-add them to the session + if errors: + Session.flash('errors', errors) return request def after(self, request, _):