-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running into non-exhaustive pattern match with groupBy #25
Comments
I've only just given this a look, but it could be related to: prowdsponsor/esqueleto#87 or prowdsponsor/esqueleto#88 Otherwise it could just be an absent explicit composite key error. I'm stuck in an airport right now. I'll do a more thorough peek around when I am home. If you have more information or a more complete repro please share it here. |
Here we go. Boilerplate: {-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Test where
import Control.Monad.IO.Class (liftIO)
import Database.Esqueleto
import qualified Database.Persist.Sqlite as S
import Database.Persist.TH
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Person
name String
age Int Maybe
Primary name
deriving Show
BlogPost
title String
authorId PersonId
Primary title
deriving Show
|]
main :: IO ()
main = S.runSqlite ":memory:" $ do
runMigration migrateAll
johnId <- insert $ Person "John Doe" $ Just 35
janeId <- insert $ Person "Jane Doe" Nothing
insert $ BlogPost "My fr1st p0st" johnId
insert $ BlogPost "One more for good measure" johnId
-- actual test code goes here So, this works pretty much as one would expect: join <- select $ from $
\ ( person `InnerJoin` post ) -> do
on $ person ^. PersonId ==. post ^. BlogPostAuthorId
return (person ^. PersonId, post ^. BlogPostId)
liftIO $ print join returns [ (Value (PersonKey {unPersonKey = "John Doe"}),Value (BlogPostKey {unBlogPostKey = "My fr1st p0st"}))
, (Value (PersonKey {unPersonKey = "John Doe"}),Value (BlogPostKey {unBlogPostKey = "One more for good measure"}))
] Now let's try to apply a (join :: [(Value (Key Person), Value Int)]) <- select $ from $
\ ( person `InnerJoin` post ) -> do
on $ person ^. PersonId ==. post ^. BlogPostAuthorId
groupBy (person ^. PersonId)
return (person ^. PersonId, count $ post ^. BlogPostId)
liftIO $ print join here I get
Okay. But avoiding (join :: [(Value (Key Person), Value Int)]) <- select $ from $
\ ( person `InnerJoin` post ) -> do
on $ person ^. PersonId ==. post ^. BlogPostAuthorId
groupBy (person ^. PersonName)
return (person ^. PersonId, count $ post ^. BlogPostId)
liftIO $ print join yields [(Value (PersonKey {unPersonKey = "John Doe"}),Value 2)] Does this make sense? Intuitively, I would expect As far as I can tell, this should be relatively straightforward to fix, but I'm not familiar enough with either persistent or esqueleto code base to say what that fix should actually be. |
P.S. You may notice that prowdsponsor/esqueleto#88 didn't update |
Same issue here :/ |
@lierdakil @alebon Friends, Russians, countrymen...lend me your ears. I have a PR over yonder. If you could confirm that this fixes the issue for you, I'd be very grateful. Tho', I'm already grateful because you made this bug a lot easier to suss out. Thank you! |
No reply so I am going forward with this, hopefully it sorts you out. |
http://hackage.haskell.org/package/esqueleto-2.5.2 is now released, please let me know if this fixed your problem. Thank you again for the very detailed and helpful bug report! |
As far as I can tell, this happens when I use
EntityId
ingroupBy
where primary key is defined asPrimary key
instead ofId
.The text was updated successfully, but these errors were encountered: