From 19f4b26e1f3edce2e3a5f66691604f014db56d80 Mon Sep 17 00:00:00 2001 From: Alexey Zabelin Date: Wed, 13 Nov 2019 20:55:47 -0800 Subject: [PATCH] Add a warning about DB actions getting rolled back --- yesod-core/src/Yesod/Core/Handler.hs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/yesod-core/src/Yesod/Core/Handler.hs b/yesod-core/src/Yesod/Core/Handler.hs index 93c6eb8a..d0917acc 100644 --- a/yesod-core/src/Yesod/Core/Handler.hs +++ b/yesod-core/src/Yesod/Core/Handler.hs @@ -91,7 +91,8 @@ module Yesod.Core.Handler , permissionDeniedI , invalidArgs , invalidArgsI - -- ** Short-circuit responses. + -- ** Short-circuit responses + -- $rollbackWarning , sendFile , sendFilePart , sendResponse @@ -607,6 +608,20 @@ setMessageI = addMessageI "" getMessage :: MonadHandler m => m (Maybe Html) getMessage = fmap (fmap snd . listToMaybe) getMessages +-- $rollbackWarning +-- +-- Note that since short-circuiting is implemented by using exceptions, +-- using e.g. 'sendStatusJSON' inside a runDB block +-- will result in the database actions getting rolled back: +-- +-- @ +-- runDB $ do +-- userId <- insert $ User "username" "email@example.com" +-- postId <- insert $ BlogPost "title" "hi there!" +-- /The previous two inserts will be rolled back./ +-- sendStatusJSON Status.status200 () +-- @ + -- | Bypass remaining handler code and output the given file. -- -- For some backends, this is more efficient than reading in the file to