Skip to content

justList breaks type-safety #432

@NorfairKing

Description

@NorfairKing

This query:

    mBool <- selectOne $ do
      pure $ val Nothing `in_` justList (valList [1, 2, 3 :: Int])
    liftIO $ print mBool

Shows me:

  PersistMarshalError "Failed to parse Haskell type `Bool`; expected boolean, integer, or bytestring of '1' or '0' from database, but received: PersistNull. Potential solution: Check that your database schema matches your Persistent model definitions."
  HasCallStack backtrace:
    collectBacktraces, called at libraries/ghc-internal/src/GHC/Internal/Exception.hs:169:13 in ghc-internal:GHC.Internal.Exception
    toExceptionWithBacktrace, called at libraries/ghc-internal/src/GHC/Internal/IO.hs:260:11 in ghc-internal:GHC.Internal.IO
    throwIO, called at ./Control/Monad/Trans/Resource.hs:195:13 in resourcet-1.3.0-BnXEVAikP2m1jrdnAev1wT:Control.Monad.Trans.Resource

In other words, the type of in_ is a lie, and should return Value (Maybe Bool) instead of Value Bool when the first argument can be NULL.

I ran this test on SQLite. I'm not sure what would/should happen on PostgreSQL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions