yesodweb / yesodweb/persistent
Natural/Composite key and IN (<-.) operator returning wrong results
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 486
- Forks
- 306
- PR merge metrics
- No merged PRs in 30d
Description
share
[mkPersist sqlSettings, mkMigrate "migrateAll"]
[persistLowerCase|
Person
tid Text
index Word
age Int Maybe
Primary tid index
deriving Show
|]
action :: ReaderT SqlBackend (NoLoggingT (ResourceT IO)) ()
action = do
deleteWhere ([] :: [Filter Person])
_ <- insert $ Person "tid1" 0 (Just 10)
_ <- insert $ Person "tid1" 1 (Just 11)
hmm <- selectList [PersonId <-. [PersonKey "tid1" 0, PersonKey "tid2" 1]] []
liftIO $ print hmm
returns
[Entity {entityKey = PersonKey {personKeytid = "tid1", personKeyindex = 0}, entityVal = Person {personTid = "tid1", personIndex = 0, personAge = Just 10}},Entity {entityKey = PersonKey {personKeytid = "tid1", personKeyindex = 1}, entityVal = Person {personTid = "tid1", personIndex = 1, personAge = Just 11}}]
It should only return ("tid1", 0). Interestingly if I filter using
[PersonKey "tidlasdjflajsd1" 0, PersonKey "tid2" 1]
It returns []
It was deleting rows for mysterious reasons, and pretty broken, unless my intuition about (<-.) and filters is completely wrong. I thought it would translate to where (tid, index) IN (('tid1', 0), ('tid2', 1)). A workaround seems to be FilterOr a list of ==.?
I figured out how to get the SQL being used
SELECT "tid", "index", "age" FROM "person" WHERE ((("tid" IN ( ?, ?) ) and ("index" IN ( ?, ?) ))); [PersistText "tid1",PersistText "tid2",PersistInt64 0,PersistInt64 1]
so definitely not what I expected.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the selectList entry point and the PersonId <-. filter handling, using the provided action and generated SQL to reproduce the composite-key query. Trace why the key components become independent IN clauses; done means the query returns only matching key pairs such as ("tid1", 0), without affecting unrelated rows.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100