Merge pull request #1640 from alexeyzab/mention-db-rollback

Add a warning about DB actions getting rolled back
This commit is contained in:
Michael Snoyman 2019-11-14 14:01:22 +05:30 committed by GitHub
commit bce08f6d86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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