Skip to content

source-klaivyo-native: better sorting and filtering handling#4062

Open
Alex-Bair wants to merge 3 commits intomainfrom
bair/source-klaivyo-native-sorting-and-filtering-handling
Open

source-klaivyo-native: better sorting and filtering handling#4062
Alex-Bair wants to merge 3 commits intomainfrom
bair/source-klaivyo-native-sorting-and-filtering-handling

Conversation

@Alex-Bair
Copy link
Member

Description:

This PR's scope addresses some connector bugs where the Klaviyo API is not sorting / filtering results as expected:

  • When filtering results, the Klaviyo API would sometimes return documents whose cursor field was at the lower bound when filtering with the greater-than operator. These are now skipped.
  • When requesting archived email campaigns, we've observe the Klaviyo API consistently return records in slightly unsorted order, despit the inclusion of a sort query parameter. This caused the connector to crash with a Received documents out of order from the Klaviyo API. error since the connector validates the "records are sorted" assumption. An assume_sorted flag on IncrementalStream now relaxed that assumption and associated check. Only the EmailCampaignsArchived has assume_sorted set to False for now. If we observe more streams receive unsorted results, we can set their assume_sorted to False as needed or potentially come up with a more robust solution.

Workflow steps:

(How does one use this feature, and how has it changed)

Documentation links affected:

(list any documentation links that you created, or existing ones that you've identified as needing updates, along with a brief description)

Notes for reviewers:

(anything that might help someone review this PR)

`fetch_incremental_resources` assumed that using the
`LowerBoundOperator.GREATER_THAN` caused Klaviyo to _not_ return results
whose cursor field was at the lower bound. Turns out, that's not
necessarily true, and the Klaviyo API sometimes returns results that are
on the lower bound when using the greater than operator. We can easily
address this by just ignoring any results received that are not greater
than the log cursor.
…mail campaigns

The Klaviyo API occasionally returns archived email campaigns in slightly
unsorted order despite the `sort` query parameter, causing the connector to
crash with a "Received documents out of order from the Klaviyo API." error.

This commits adds an `assume_sorted` flag to `IncrementalStream`. For streams
where it's `True`, we continue validating the API returns results in sorted order and
emitting checkpoints before processing the entire set of results. For streams
where it's `False`, we now skip the ordering validation and only checkpoint
after emitting all documents in the set of results.

Since we've consistently observed the Klaviyo API return archived email
campaigns in unsorted order, this commit also sets `assume_sorted` on
the `EmailCampaignsArchived` class to `False`. We've only observed
the `EmailCampaignsArchived` stream receive unsorted results, so I'm
holding off setting `assume_sorted=False` for any other streams for now.
If we observe more `Received documents out of order from the Klaviyo API`
for other streams, we can either set `assume_sorted=False` on more streams
or find a more robust general purpose solution.
@Alex-Bair Alex-Bair marked this pull request as ready for review March 23, 2026 21:06
@Alex-Bair Alex-Bair requested a review from a team March 23, 2026 21:06
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

Successfully merging this pull request may close these issues.

1 participant