Skip to content

fix(enable-banking): preserve claimed pending date on subsequent syncs#1797

Merged
jjmata merged 1 commit into
we-promise:mainfrom
CrossDrain:eb-fix-claimed-pending-date-persistence
May 14, 2026
Merged

fix(enable-banking): preserve claimed pending date on subsequent syncs#1797
jjmata merged 1 commit into
we-promise:mainfrom
CrossDrain:eb-fix-claimed-pending-date-persistence

Conversation

@CrossDrain
Copy link
Copy Markdown
Contributor

@CrossDrain CrossDrain commented May 14, 2026

Problem

PR #1783 preserved the original pending transaction date on the first sync by capturing pending_entry_date from the pending match. However, on every subsequent sync the date gets silently overwritten with the booked settlement date.

Why: On subsequent syncs the entry is found by its booked external_id — it's not a new record, so the pending_match path is never entered and pending_entry_date stays nil. The expression nil || date then falls through to the incoming booked date.

Solution

Add a three-way date resolution before assign_attributes:

  1. First claim — use pending_entry_date (captured from the pending match, same as before)
  2. Subsequent syncs — if the entry is existing and auto_claimed_pending_ids is present in extra (the signal written during the first claim), keep entry.date unchanged
  3. Normal case — use the incoming provider date

Testing

  • Added "preserves pending date on subsequent syncs after auto-claim" test: imports a pending entry, claims it with a booked entry, then re-imports the same booked entry and asserts the date hasn't changed.
  • All existing pending/claim tests continue to pass.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved transaction date handling during provider syncs. Transaction dates are now preserved correctly when pending transactions are confirmed and later re-synced, preventing unintended date changes.

Review Change Stack

After the first sync claims a pending entry (setting auto_claimed_pending_ids),
subsequent syncs find the entry by booked external_id as an existing record.
pending_match is never entered so pending_entry_date stays nil, causing
`nil || date` to silently overwrite the preserved pending date with the
booked settlement date.

Fix by checking auto_claimed_pending_ids on the existing entry — its presence
signals a prior auto-claim, so entry.date (the original pending date) is kept.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@superagent-security superagent-security Bot added contributor:verified Contributor passed trust analysis. pr:verified PR passed security analysis. labels May 14, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1a5ed201-9021-4ecc-b054-f587c70f39a2

📥 Commits

Reviewing files that changed from the base of the PR and between 81e6687 and 8c59335.

📒 Files selected for processing (2)
  • app/models/account/provider_import_adapter.rb
  • test/models/account/provider_import_adapter_test.rb

📝 Walkthrough

Walkthrough

Modified Account::ProviderImportAdapter#import_transaction to preserve an auto-claimed pending transaction's original date across subsequent syncs. The method now computes an effective_date that uses the stored entry date when the transaction carries the auto_claimed_pending_ids marker, preventing later syncs from overwriting it with the booked date. A test verifies this behavior.

Changes

Pending Transaction Date Preservation

Layer / File(s) Summary
Preserve auto-claimed pending transaction date on re-import
app/models/account/provider_import_adapter.rb, test/models/account/provider_import_adapter_test.rb
import_transaction computes effective_date to keep the original pending date stable when transaction.extra["auto_claimed_pending_ids"] is present, preventing later syncs from replacing it. Test verifies that re-imported booked transactions retain the originally captured pending date.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • we-promise/sure#1783: Both PRs update Account::ProviderImportAdapter#import_transaction to preserve the originally auto-claimed pending transaction date using pending_entry_date and transaction.extra["auto_claimed_pending_ids"] to prevent later syncs from overwriting it.

Suggested labels

contributor:verified, pr:verified

Suggested reviewers

  • jjmata

Poem

🐰 A pending date, once claimed as true,
Now keeps its story bright and new,
Through syncs and claims it stands its ground,
The original moment, forever found! 💫

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the main change: preserving the claimed pending transaction date during subsequent syncs, which is exactly what the changeset addresses.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@jjmata jjmata merged commit c106aaf into we-promise:main May 14, 2026
10 checks passed
@sure-admin sure-admin modified the milestones: v0.7.1, v0.7.2 May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor:verified Contributor passed trust analysis. pr:verified PR passed security analysis.

Development

Successfully merging this pull request may close these issues.

3 participants