Skip to content

deleteBy is broken in some cases #1581

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

Open
functora opened this issue Apr 7, 2025 · 2 comments
Open

deleteBy is broken in some cases #1581

functora opened this issue Apr 7, 2025 · 2 comments

Comments

@functora
Copy link

functora commented Apr 7, 2025

Function deleteBy is broken in cases where at least one of the fields of composite unique key is nullable.

@parsonsmatt
Copy link
Collaborator

Hm, that's not good. Can you describe the behavior you observe?

@functora
Copy link
Author

functora commented Apr 8, 2025

Here is an example:

deleteDir ::
  BotId ->
  Maybe DirId ->
  Integer ->
  ReaderT SqlBackend IO ()
deleteDir botId mParId idx =
  --
  -- NOTE : esqueleto query always works, but vanilla persistent
  -- query is not working in cases where mParId == Nothing,
  -- probably null /= null sql problems here...
  --
  -- P.deleteBy $ UniqueDir botId mParId idx
  --
  delete . from $ \dir ->
    where_
      $ ( dir ^: DirBotId ==. val botId
        )
      &&. ( dir ^: DirParentId & case mParId of
              Nothing -> isNothing
              Just parId -> (==. val (Just parId))
          )
      &&. ( dir ^: DirIdx ==. val idx
          )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants