Skip to content

fix(PMNT-111): fix pagination on MangoPay #458

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

Merged
merged 5 commits into from
Jun 4, 2025
Merged

Conversation

fguery
Copy link
Contributor

@fguery fguery commented May 27, 2025

This fixes 2 issues:

  • Payments might not all get processed, as we were updating both Page & CreatedAt in the state -- so let's say we process page 2 of createdAt=2021, the next execution would be page 3 of createdAt=2022 (or whatever the last createdAt use to be). This fixes the issue by resetting to page=1 whenever the createdAt state changes
  • THe other issue is one that is highlighted in PMNT-111, where, if multiple payment/account/external accounts/users are created at the same time, we will not process them if they're spread across pages (if the oldState.lastCreatedAt is equal to the current entity being processed)

@fguery fguery requested a review from a team as a code owner May 27, 2025 07:57
Copy link
Contributor

coderabbitai bot commented May 27, 2025

Walkthrough

The changes refactor pagination logic in Mangopay connector components to handle cases where multiple entities share the same creation date. The code now allows processing of entities whose creation date equals the last processed date and adjusts state management to increment the page when needed. Associated tests are updated and expanded to cover these scenarios.

Changes

File(s) Change Summary
internal/connectors/plugins/public/mangopay/accounts.go,
external_accounts.go,
users.go
Refactored filtering logic: replaced switch with if statement to allow processing of entities with creation date equal to last processed date.
internal/connectors/plugins/public/mangopay/payments.go Disabled trimming of payments slice; updated state logic to increment page when last payment's date equals previous state's date.
internal/connectors/plugins/public/mangopay/accounts_test.go,
external_accounts_test.go,
users_test.go
Updated existing tests to new creation date logic; added test cases for equal creation date scenarios across pages.
internal/connectors/plugins/public/mangopay/payments_test.go Added test for handling payments with identical creation dates at page boundaries.
test/e2e/api_payment_initiations_test.go Marked transfer and payout initiation tests as serial to enforce sequential execution.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Connector
    participant MangopayAPI

    Client->>Connector: Request next page (with lastCreationDate, lastPage)
    Connector->>MangopayAPI: Fetch entities (with page, pageSize)
    MangopayAPI-->>Connector: Return entities (some may have same creation date)
    Connector->>Connector: Filter entities (creationDate >= lastCreationDate)
    alt Last entity's creationDate == lastCreationDate
        Connector->>Connector: Increment lastPage
    else
        Connector->>Connector: Reset lastPage to 1
    end
    Connector-->>Client: Return entities, new state (lastCreationDate, lastPage)
Loading

Assessment against linked issues

Objective Addressed Explanation
Correct pagination when multiple entities share the same lastUpdatedAt/creationDate (PMNT-111)
Combine lastUpdatedAt and page to fetch next results in case of batch updates (PMNT-111)
Update state logic to increment page when last entity’s date matches previous state (PMNT-111)
Add/adjust tests to verify correct pagination in edge cases (PMNT-111)

Poem

A hop and a skip through the pages we go,
Where dates are the same, the logic must flow.
No more confusion when batches align—
The rabbit ensures your results are just fine!
With tests all a-bounce and code now pristine,
Pagination’s as smooth as a field of green.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f83a3f3 and 5b4ff67.

📒 Files selected for processing (1)
  • test/e2e/api_payment_initiations_test.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • test/e2e/api_payment_initiations_test.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Tests
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
internal/connectors/plugins/public/moneycorp/external_accounts.go (1)

95-103: 🛠️ Refactor suggestion

Remove redundant filtering logic.

The new conditional check is redundant with the existing switch statement below. The if createdAt.Before(lastCreatedAt) check will filter out all cases that the switch statement's -1, 0 cases would handle, making the switch statement unreachable for those conditions.

Consolidate the filtering logic by removing either the new if statement or the switch statement:

-		// TODO we have the potential to skip some here, we should use strict lower
-		if createdAt.Before(lastCreatedAt) {
-			continue
-		}
-		switch createdAt.Compare(lastCreatedAt) {
-		case -1, 0:
-			continue
-		default:
-		}
+		if createdAt.Before(lastCreatedAt) {
+			continue
+		}

Or if you want to maintain the equal-timestamp filtering for now, keep only the switch statement until the pagination logic is properly updated to handle timestamp collisions.

🧹 Nitpick comments (1)
internal/connectors/plugins/public/moneycorp/payments.go (1)

45-45: Address the pagination issue identified in the TODO comment.

This TODO comment indicates the same pagination problems that were fixed in the MangoPay connector. The current implementation may miss entities when multiple items share the same LastCreatedAt timestamp across pages, which is exactly the issue described in PMNT-111.

Consider implementing a similar fix to the MangoPay approach shown in the other files in this PR. Would you like me to propose a solution that handles timestamp collisions and proper page management?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 46f6b13 and 67cbafd.

📒 Files selected for processing (10)
  • internal/connectors/plugins/public/mangopay/accounts.go (1 hunks)
  • internal/connectors/plugins/public/mangopay/accounts_test.go (2 hunks)
  • internal/connectors/plugins/public/mangopay/external_accounts.go (1 hunks)
  • internal/connectors/plugins/public/mangopay/external_accounts_test.go (2 hunks)
  • internal/connectors/plugins/public/mangopay/payments.go (1 hunks)
  • internal/connectors/plugins/public/mangopay/payments_test.go (1 hunks)
  • internal/connectors/plugins/public/mangopay/users.go (1 hunks)
  • internal/connectors/plugins/public/mangopay/users_test.go (2 hunks)
  • internal/connectors/plugins/public/moneycorp/external_accounts.go (1 hunks)
  • internal/connectors/plugins/public/moneycorp/payments.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
internal/connectors/plugins/public/mangopay/users_test.go (1)
internal/models/plugin.go (1)
  • FetchNextOthersRequest (98-103)
internal/connectors/plugins/public/mangopay/accounts_test.go (2)
internal/models/plugin.go (1)
  • FetchNextAccountsRequest (62-66)
internal/connectors/engine/workflow/workflow.go (1)
  • FromPayload (18-21)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Tests
🔇 Additional comments (12)
internal/connectors/plugins/public/mangopay/users.go (1)

89-91: LGTM! Simplifies logic and fixes timestamp collision issue.

This change correctly addresses the pagination issue described in PMNT-111. By changing from filtering <= lastCreationDate to < lastCreationDate, entities with the same creation timestamp as the last processed item will now be included in subsequent pages, preventing entities from being skipped when timestamps collide across page boundaries.

internal/connectors/plugins/public/mangopay/external_accounts.go (1)

95-97: LGTM! Consistent fix for timestamp collision pagination issue.

This change mirrors the fix in users.go and correctly addresses the pagination problem where external accounts with the same creation date could be missed across page boundaries. The simplified logic improves readability while ensuring entities with identical timestamps are properly processed.

internal/connectors/plugins/public/mangopay/payments.go (2)

70-74: Important behavioral change documented well.

The comment clearly explains why data trimming is skipped to prevent data loss during page transitions. This is a crucial behavioral change that could result in up to 2x the requested page size being returned, which callers should be aware of.


77-83: Correct implementation of pagination state management fix.

The conditional logic properly addresses the first issue mentioned in the PR objectives:

  • When the creation date remains the same, the page is incremented
  • When the creation date changes, the page resets to 1

This ensures proper pagination flow when transitioning between different creation timestamps.

internal/connectors/plugins/public/mangopay/accounts.go (1)

98-100: Correct fix for handling entities with equal creation timestamps.

The simplified conditional logic properly addresses the second issue mentioned in the PR objectives. By changing from <= (switch statement) to strictly < (Before), accounts created at the same timestamp as the last processed date are now included, ensuring all entities are processed across page boundaries.

internal/connectors/plugins/public/mangopay/users_test.go (2)

145-145: Index correction aligns with consistent test data setup.

The change from index 38 to 39 ensures consistency with the test setup and aligns with similar changes in accounts_test.go.


177-204: Excellent test coverage for overlapping creation dates scenario.

This test case effectively validates the fix for the second pagination issue:

  • Sets up overlapping creation dates (users[9] and users[10])
  • Starts pagination from the boundary condition
  • Verifies all users with equal timestamps are processed correctly
  • Confirms proper state management

The test thoroughly covers the edge case mentioned in PMNT-111.

internal/connectors/plugins/public/mangopay/accounts_test.go (2)

158-158: Index correction maintains test consistency.

The change from index 38 to 39 aligns with the corresponding change in users_test.go, ensuring consistent test data setup across entity types.


190-216: Comprehensive test coverage for edge case scenario.

This test case mirrors the users_test.go implementation and provides excellent coverage for the overlapping creation dates scenario:

  • Simulates accounts created at the same timestamp
  • Tests pagination boundary conditions
  • Validates correct state transitions
  • Ensures all accounts are processed despite timestamp overlap

The test effectively validates the filtering logic fix in accounts.go.

internal/connectors/plugins/public/mangopay/external_accounts_test.go (2)

146-146: Good fix for test accuracy.

Changing the index from 38 to 39 correctly references the last account from the first page (with pageSize 40), making the test more logically consistent with the pagination scenario being tested.


178-205: Excellent test coverage for edge case handling.

This new test case effectively validates the pagination fix mentioned in the PR objectives - specifically testing the scenario where multiple entities share the same creation timestamp across page boundaries. The test:

  • Correctly simulates the edge case by setting sampleBankAccounts[10].CreationDate = sampleBankAccounts[9].CreationDate
  • Properly mocks the client call to return the expected page slice
  • Validates that pagination advances correctly (page increments to 2)
  • Ensures the state is updated with the correct last creation date

This directly addresses the PMNT-111 issue where entities with equal timestamps could be missed during pagination.

internal/connectors/plugins/public/mangopay/payments_test.go (1)

180-215: Comprehensive test for timestamp collision scenario.

This test case excellently covers the critical edge case where all entities have identical creation timestamps. The implementation:

  • Simulates extreme conditions: Sets all transactions to the same creation date to test the most challenging pagination scenario
  • Validates correct pagination behavior: Ensures the page advances from 1 to 2 even when timestamps are identical
  • Maintains state consistency: Verifies that LastCreationDate remains unchanged while LastPage increments correctly
  • Uses realistic mock expectations: The mocked client call matches the expected parameters for this pagination scenario

This directly addresses the first issue mentioned in the PR objectives where page number and createdAt timestamp management could cause incorrect pagination flow.

Copy link

codecov bot commented May 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.09%. Comparing base (5e6dc37) to head (5b4ff67).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #458      +/-   ##
==========================================
- Coverage   69.11%   69.09%   -0.03%     
==========================================
  Files         601      601              
  Lines       30605    30593      -12     
==========================================
- Hits        21153    21138      -15     
- Misses       8337     8339       +2     
- Partials     1115     1116       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

case -1, 0:
// creationDate <= state.LastCreationDate, nothing to do,
// we already processed this bank account.
if creationDate.Before(oldState.LastCreationDate) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we are using Compare + switch statements instead of .Before and .Equal?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not. Many of these connectors were made by freelancers/employees who are no longer here so the style is not really fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since before is only sending true if t1 < t2, we wanted to check the egality also if i remember correctly

if !needMore {
payments = payments[:req.PageSize]
}
// Note that we are NOT trimming data as in other connectors to respect the pageSize; doing so would mean we could
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qonto behaves like that; I might have to apply it elsewhere going forward.
We can fix it to make it work with a fixed length returned, but it's a bit of added complexity that I'm happy to not do if we don't need it.

I also think it's useful to leave the comment, LMK if you disagree.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am for leaving comments that explain some technicalities that might not be obvious on first glance 👍

@@ -92,6 +92,10 @@ func recipientToPSPAccounts(
return accounts, fmt.Errorf("failed to parse transaction date: %v", err)
}

// TODO we have the potential to skip some here, we should use strict lower
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops I didn't mean to commit that

@fguery fguery added this pull request to the merge queue May 27, 2025
case -1, 0:
// creationDate <= state.LastCreationDate, nothing to do,
// we already processed this account.
if accountCreationDate.Before(oldState.LastCreationDate) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure, Before() is only sending true if t1 < t2 and sending false when t1 = t2. This is what you want ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as answered on Slakc (leaving it here instead for posterity)
We need to process it when dates are equal; if not we are at risk of not processing some new records (see PMNT-111)

@paul-nicolas paul-nicolas removed this pull request from the merge queue due to a manual request May 27, 2025
@fguery fguery added this pull request to the merge queue May 27, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 27, 2025
@fguery fguery added this pull request to the merge queue Jun 2, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 2, 2025
@fguery fguery force-pushed the PMNT-111_fix-pagination branch from ede402c to f83a3f3 Compare June 4, 2025 09:56
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
internal/connectors/plugins/public/mangopay/accounts_test.go (1)

190-190: Fix typo in test description.

There's a grammatical error in the test name.

-		It("should fetch next accounts - when lastCreationDate form last page is equal to one of the new page's", func(ctx SpecContext) {
+		It("should fetch next accounts - when lastCreationDate from last page is equal to one of the new page's", func(ctx SpecContext) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 67cbafd and f83a3f3.

📒 Files selected for processing (9)
  • internal/connectors/plugins/public/mangopay/accounts.go (1 hunks)
  • internal/connectors/plugins/public/mangopay/accounts_test.go (2 hunks)
  • internal/connectors/plugins/public/mangopay/external_accounts.go (1 hunks)
  • internal/connectors/plugins/public/mangopay/external_accounts_test.go (2 hunks)
  • internal/connectors/plugins/public/mangopay/payments.go (1 hunks)
  • internal/connectors/plugins/public/mangopay/payments_test.go (1 hunks)
  • internal/connectors/plugins/public/mangopay/users.go (1 hunks)
  • internal/connectors/plugins/public/mangopay/users_test.go (2 hunks)
  • test/e2e/api_payment_initiations_test.go (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • test/e2e/api_payment_initiations_test.go
🚧 Files skipped from review as they are similar to previous changes (7)
  • internal/connectors/plugins/public/mangopay/users.go
  • internal/connectors/plugins/public/mangopay/payments.go
  • internal/connectors/plugins/public/mangopay/external_accounts.go
  • internal/connectors/plugins/public/mangopay/accounts.go
  • internal/connectors/plugins/public/mangopay/users_test.go
  • internal/connectors/plugins/public/mangopay/payments_test.go
  • internal/connectors/plugins/public/mangopay/external_accounts_test.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Tests
🔇 Additional comments (2)
internal/connectors/plugins/public/mangopay/accounts_test.go (2)

158-158: LGTM! The test setup correctly references the 40th account (index 39).

The change aligns with the updated pagination logic and properly sets up the test state for the pagination scenario.


191-216: Well-designed test case for the pagination fix.

This test case effectively validates the core fix mentioned in the PR objectives - ensuring that entities with creation dates equal to the last processed creation date are properly handled across pages. The test setup is comprehensive:

  • Correctly simulates the scenario where two accounts have the same creation timestamp
  • Properly configures the pagination state with lastPage: 2
  • Uses appropriate mock expectations
  • Validates both the returned accounts and the updated state

The test logic aligns perfectly with the pagination fix that allows processing entities whose creation date equals the last processed date.

@fguery fguery added this pull request to the merge queue Jun 4, 2025
Merged via the queue into main with commit 998ec0a Jun 4, 2025
9 checks passed
@fguery fguery deleted the PMNT-111_fix-pagination branch June 4, 2025 12:03
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.

3 participants