justList breaks type-safety

Open
#432 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
haskell, postgresql, sqlite
Domain
databases

Research direction

Start with the reported SQLite reproduction using selectOne, in_, justList, and valList, then inspect the type signatures and implementation of in_ and justList. Compare the NULL behavior on SQLite and PostgreSQL, and consider the issue done when the inferred result type matches nullable values and coverage verifies the behavior on the supported database backends.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Haskell
Stars
401
Forks
108
PR merge metrics
No merged PRs in 30d

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bitemyapp/esqueleto

All issues in bitemyapp/esqueleto

Similar issues

More Haskell issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.