Skip to content

Bug: Events API - missing records in paginated results due to duplicate timestamps #34143

@luke-belton

Description

@luke-belton

Bug Description

Bug description

The events API (/api/projects/:project_id/events), and possibly other endpoints, may miss records from paginated results where there are duplicate timestamps in the results.

This is caused by the next key on the response object using before with a timestamp to define the next page of results - e.g. "next":"https://us.posthog.com/api/projects/:project_id/events/?before=2025-06-25T09%3A58%3A42.921000%2B00%3A00". If the before timestamp is seen on multiple events across a page boundary, then the events that should have appeared at the start of the next page of results are skipped.

We do appear to use offset based pagination elsewhere.

Using the query API to fetch events with offset based pagination can be used as a workaround for this issue.

Additional context

From: https://posthoghelp.zendesk.com/agent/tickets/33156

Debug info

Kind: bug

Target area: data_management

Report event: http://go/ticketByUUID/a3567211-4b58-44fd-9ab1-a07f9e33fcc9

Session: https://us.posthog.com/project/sTMFPsFhdP1Ssg/replay/0197a2e6-fdd7-7219-89f6-d13f2218fd75?t=10036

Exceptions: https://us.posthog.com/project/2/error_tracking?filterGroup=%7B%22type%22%3A%22AND%22%2C%22values%22%3A%5B%7B%22type%22%3A%22AND%22%2C%22values%22%3A%5B%7B%22key%22%3A%22%24session_id%22%2C%22value%22%3A%5B%220197a2e6-fdd7-7219-89f6-d13f2218fd75%22%5D%2C%22operator%22%3A%22exact%22%2C%22type%22%3A%22event%22%7D%5D%7D%5D%7D

Location: https://us.posthog.com/project/184456/activity/explore#q=%7B%22kind%22%3A%22DataTableNode%22%2C%22full%22%3Atrue%2C%22source%22%3A%7B%22kind%22%3A%22EventsQuery%22%2C%22select%22%3A%5B%22*%22%2C%22event%22%2C%22properties.source%22%2C%22properties.type%22%2C%22timestamp%22%5D%2C%22orderBy%22%3A%5B%22timestamp%20DESC%22%5D%2C%22after%22%3A%22all%22%2C%22modifiers%22%3A%7B%22usePresortedEventsTable%22%3Atrue%7D%2C%22properties%22%3A%5B%5D%7D%2C%22propertiesViaUrl%22%3Atrue%2C%22showSavedQueries...&

Persons-on-events mode for project: person_id_override_properties_on_events

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working rightfeature/activityFeature Tag: Activity (fka Events)feature/api-structureFeature Tag: API structure

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions