bitemyapp / bitemyapp/esqueleto

justList breaks type-safety

Open
#432 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
399
Forks
107
Avg merge
1d 17h
Merged PRs (30d)
1

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.

Contributor guide

No contributing guide indexed for this repository

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.