Skip to content

Bug in skip parameter and nextBatch function. #160

@regellosigkeitsaxiom

Description

@regellosigkeitsaxiom

I encountered a bug in skip parameter and nextBatch function: skip does not have any effect, nextBatch causes internal error with fromJust.

Example function which breaks with bug:

findAll :: Query -> Action IO [Document]
findAll q = go 0
  where
  pageSize :: Word32
  pageSize = 1
  go :: Word32 -> Action IO [Document]
  go offset = do
    cc <- find q { sort = [ "_id" =: 1 ], skip = offset, limit = pageSize, batchSize = pageSize }
    batch <- rest cc
    liftIO $ putStrLn $ "Data: +" <> show ( length batch ) <> " to " <> show offset
    mapM_ (\x -> liftIO $ print $ docId x ) batch
    if length batch < fromIntegral pageSize || offset >= 10 {-So we will not run infinitely with bug-}
      then return batch
      else (batch ++) <$> go (offset + pageSize )

It iterates over same item (infinitely in normal scenario).

Spent 3 hours realizing the bug is not in my code, and 10 minutes slopping a fix, which itself seems trivial. Detailed AI-generated description is in BUG.md.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions