What does "Not PersistText value" mean?
I'm new to Yesod and I'm trying to make the same blog project from this screencast: https://www.youtube.com/watch?v=SadfV-qbVg8 with the only difference being that I'm using MariaDB instead of PostgreSQL. Every time I add a new blog post and redirect to the page that shows it, I see this error:
[Error#yesod-core] get BlogPostKey {unBlogPostKey = SqlBackendKey {unSqlBackendKey = 5}}: field article: Not a PersistText value @(yesod-core-1.4.12:Yesod.Core.Class.Yesod ./Yesod/Core/Class/Yesod.hs:577:5)
What exactly does this mean? If I look into the database, I have all the records saved correctly. Why can't it download messages from the database?
Here's the code
model
User
ident Text
password Text Maybe
UniqueUser ident
deriving Typeable
Email
email Text
user UserId Maybe
verkey Text Maybe
UniqueEmail email
BlogPost
title Text
article Markdown
PostDetails.hs (gets message from DB and shows it)
module Handler.PostDetails where
import Import
getPostDetailsR :: BlogPostId -> Handler Html
getPostDetailsR blogPostId = do
blogPost <- runDB $ get404 blogPostId
defaultLayout $ do
$(widgetFile "postDetails/post")
PostNew.hs (Creates a new message and saves it to the database, after insertion, redirects it to PostDetails.hs with a new message)
module Handler.PostNew where
import Import
import Yesod.Form.Bootstrap3
import Yesod.Text.Markdown
blogPostForm :: AForm Handler BlogPost
blogPostForm = BlogPost
<$> areq textField (bfs ("Title" :: Text)) Nothing
<*> areq markdownField (bfs ("Article" :: Text)) Nothing
getPostNewR :: Handler Html
getPostNewR = do
(widget, enctype) <- generateFormPost $ renderBootstrap3 BootstrapBasicForm blogPostForm
defaultLayout $ do
$(widgetFile "posts/new")
postPostNewR :: Handler Html
postPostNewR = do
((res, widget), enctype) <- runFormPost $ renderBootstrap3 BootstrapBasicForm blogPostForm
case res of
FormSuccess blogPost -> do
blogPostId <- runDB $ insert blogPost
redirect $ PostDetailsR blogPostId
_ -> defaultLayout $(widgetFile "posts/new")
I don't understand why the compiler didn't catch this error. When I create a post, I use "Internal Server Error" instead of the header
source to share
This turned out to be caused by a bug in the package persistent-mysql
, which is now fixed in persistent-mysql-2.3
.
Here is the main reason for those interested:
The MySQL C library (and also the extension to the Haskell package mysql
it depends on persistent-mysql
) does not distinguish between binary and text data at the type level. So if you stored the value TEXT
in the database when it looked persistent, it ended up being binary (a PersistByteString
).
This was fixed in # 451 by checking the column character set, which is recommended by the MySQL API guidelines as a suitable solution.
See pull request or this issue for more information .
Thanks for asking this question; I would not have realized there was an error otherwise.
source to share