Skip to content
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

✨ Bank sync avoid reimporting deleted transactions #4644

Conversation

alecbakholdin
Copy link
Contributor

When you import a transaction using bank-sync, delete it, then re-import it, the transaction gets reimported instead of getting ignored. The reason for this is the v_transactions view filters out deleted transactions. I've updated the matchTransactions method to use the v_transactions_internal "view" (js-defined, looks like?), which includes deleted transactions.

@actual-github-bot actual-github-bot bot changed the title 🐛 Bank sync reimporting deleted transactions [WIP] 🐛 Bank sync reimporting deleted transactions Mar 17, 2025
Copy link

netlify bot commented Mar 17, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit e78e476
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67d98ba0f1e6c70008b17db4
😎 Deploy Preview https://deploy-preview-4644.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Mar 17, 2025

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
18 8.39 MB → 8.39 MB (+1.88 kB) +0.02%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/component-library/src/icons/v1/Question.tsx 🆕 +506 B 0 B → 506 B
src/components/banksync/EditSyncAccount.tsx 📈 +1.38 kB (+21.29%) 6.5 kB → 7.89 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 5.42 MB → 5.42 MB (+1.88 kB) +0.03%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/en-GB.js 5.37 kB 0%
static/js/nl.js 102.82 kB 0%
static/js/de.js 120.79 kB 0%
static/js/es.js 65.71 kB 0%
static/js/en.js 109.09 kB 0%
static/js/fr.js 122.17 kB 0%
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/uk.js 110.45 kB 0%
static/js/pt-BR.js 120.11 kB 0%
static/js/narrow.js 372.67 kB 0%
static/js/useAccountPreviewTransactions.js 1.69 kB 0%
static/js/AppliedFilters.js 10.87 kB 0%
static/js/wide.js 112.21 kB 0%
static/js/ReportRouter.js 1.59 MB 0%

Copy link
Contributor

github-actions bot commented Mar 17, 2025

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 2.57 MB → 2.57 MB (+250 B) +0.01%
Changeset
File Δ Size
packages/loot-core/src/server/accounts/sync.ts 📈 +290 B (+0.96%) 29.4 kB → 29.68 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
kcab.worker.js 2.57 MB → 2.57 MB (+250 B) +0.01%

Smaller

No assets were smaller

Unchanged

No assets were unchanged

@MatissJanis
Copy link
Member

This is an interesting proposal, but I can see it being somewhat controversial as it will impact existing workflows folks already have. Perhaps we allow users to configure this vis the banksync page? Similar to how "should pending transactions be imported?".

@alecbakholdin alecbakholdin changed the title [WIP] 🐛 Bank sync reimporting deleted transactions \🐛 Bank sync reimporting deleted transactions Mar 17, 2025
@alecbakholdin alecbakholdin changed the title \🐛 Bank sync reimporting deleted transactions 🐛 Bank sync reimporting deleted transactions Mar 17, 2025
@youngcw
Copy link
Member

youngcw commented Mar 17, 2025

There is also a PR that allows rules to delete transactions

@alecbakholdin alecbakholdin changed the title 🐛 Bank sync reimporting deleted transactions [WIP] 🐛 Bank sync reimporting deleted transactions Mar 17, 2025
@youngcw
Copy link
Member

youngcw commented Mar 17, 2025

This would also make it really difficult to fix unintentional deletions without some way to manually, undelete

Copy link
Contributor

coderabbitai bot commented Mar 17, 2025

Walkthrough

This pull request introduces enhancements to the transaction reconciliation process by adding two new test cases to the Account sync test suite. The first test verifies that deleted transactions are not rematched when the reimport preference is disabled, while the second test confirms that deleted transactions are rematched by default. Additionally, the matchTransactions function has been updated to include a new variable, reimportDeleted, which determines the source of transaction data based on user preferences. This change involves selecting between different SQL views for transaction retrieval. Furthermore, a new synced preference type has been added to accommodate the reimporting of deleted transactions.

Possibly related PRs

Suggested labels

:sparkles: Merged

Suggested reviewers

  • youngcw
  • MatissJanis

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 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 5b54288 and e78e476.

📒 Files selected for processing (1)
  • packages/desktop-client/src/components/banksync/EditSyncAccount.tsx (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Functional
  • GitHub Check: Visual regression
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: build (windows-latest)
🔇 Additional comments (5)
packages/desktop-client/src/components/banksync/EditSyncAccount.tsx (5)

5-5: Import additions look appropriate

The new imports for SvgQuestion, Tooltip, and View components are necessary for implementing the new feature that allows users to configure whether deleted transactions should be reimported.

Also applies to: 8-9


128-130: Good addition of the synced preference

Adding the savedReimportDeleted preference with a default value of true aligns with the PR objectives of making this feature configurable while maintaining backward compatibility (reimporting deleted transactions by default).


140-142: State implementation follows component patterns

The state implementation for reimportDeleted follows the same pattern as other preference-based states in this component, including proper string-to-boolean conversion.


180-180: Saving preference correctly implemented

The implementation of saving the reimportDeleted preference matches the pattern used for other preferences in the onSave function.


239-262:

✅ Verification successful

Well-implemented UI with helpful tooltip

The checkbox option and tooltip implementation look good and match the previous review feedback. The tooltip provides clear information about what this option does.

One consideration: users might benefit from understanding the implications of disabling this feature in more detail, especially in relation to transaction management workflows.

Verify that the preference is being properly utilized in the transaction matching logic to ensure this UI control actually affects the behavior as intended.


🏁 Script executed:

#!/bin/bash
# Search for implementation of the preference in the sync logic
rg -A 5 "sync-reimport-deleted" --glob "*.ts" --glob "*.js"

Length of output: 1553


Re-import Checkbox UI & Preference Usage Validation

The UI implementation in packages/desktop-client/src/components/banksync/EditSyncAccount.tsx looks solid—the checkbox and tooltip are well-implemented and match the earlier feedback. I verified that the corresponding preference (sync-reimport-deleted) is properly integrated into the sync logic:

  • Preference Definition & Usage:

    • The preference is defined in packages/loot-core/src/types/prefs.d.ts.
    • It’s actively used in packages/loot-core/src/server/accounts/sync.ts, where the code fetches and interprets its state.
  • Tests Confirmation:

    • The tests in packages/loot-core/src/server/accounts/sync.test.ts simulate updates to the preference, confirming that toggling this option affects the transaction reconciliation as intended.

While the current tooltip provides good context, consider expanding the explanation to further inform users about the implications of disabling this feature in their transaction management workflows.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

Sorry, something went wrong.

@alecbakholdin
Copy link
Contributor Author

alecbakholdin commented Mar 17, 2025

There is also a PR that allows rules to delete transactions

This probably functions as workaround in each specific case but not in the general case, and can potentially catch more transactions that I didn't intend to be deleted.

@MatissJanis To me this looks like a bug and not how I would expect Actual to behave; if I delete a transaction, it should stay deleted. However, after a hair more thinking I can understand people relying on this behavior so I'll make it configurable. Similar to importing pending transactions, I suppose I would call it "Reimport deleted transactions" and default it to true. If you have an alternate name that you would like me to name it let me know!

@alecbakholdin alecbakholdin changed the title [WIP] 🐛 Bank sync reimporting deleted transactions [WIP] ✨ Bank sync reimporting deleted transactions Mar 17, 2025
@alecbakholdin
Copy link
Contributor Author

alecbakholdin commented Mar 17, 2025

This would also make it really difficult to fix unintentional deletions without some way to manually, undelete

I would argue that if you manually deleted a transaction, then realized you actually want it, you can just manually enter that transaction. I don't see this as being much of an issue unless you're doing this en masse. Also, with this being an opt-in config option now, no longer really an issue.

@alecbakholdin
Copy link
Contributor Author

Image of config [on by default]:
image

@youngcw
Copy link
Member

youngcw commented Mar 17, 2025

I don't see this as being much of an issue unless you're doing this en masse

This is generally where my concern is. People getting started with bank sync, or trying to make new rules, delete transactions all the time and then expect them to show up again on the import.

I don't think this is a bad feature, but it should be opt in.

@alecbakholdin
Copy link
Contributor Author

People getting started with bank sync

Ah, that's something I hadn't considered. Sorry about that!

@alecbakholdin alecbakholdin changed the title [WIP] ✨ Bank sync reimporting deleted transactions ✨ Bank sync reimporting deleted transactions Mar 17, 2025
@alecbakholdin alecbakholdin changed the title ✨ Bank sync reimporting deleted transactions ✨ Bank sync avoid reimporting deleted transactions Mar 17, 2025
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)
packages/desktop-client/src/components/banksync/EditSyncAccount.tsx (1)

236-242: Consider updating the checkbox ID.

The ID form_deleted_notes seems inconsistent with the functionality it represents. Consider renaming it to better reflect that it's for reimporting deleted transactions.

-            id="form_deleted_notes"
+            id="form_reimport_deleted"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2bfba41 and 8687c4d.

⛔ Files ignored due to path filters (2)
  • packages/loot-core/src/server/accounts/__snapshots__/sync.test.ts.snap is excluded by !**/*.snap
  • upcoming-release-notes/4644.md is excluded by !**/*.md
📒 Files selected for processing (4)
  • packages/desktop-client/src/components/banksync/EditSyncAccount.tsx (4 hunks)
  • packages/loot-core/src/server/accounts/sync.test.ts (2 hunks)
  • packages/loot-core/src/server/accounts/sync.ts (2 hunks)
  • packages/loot-core/src/types/prefs.d.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/loot-core/src/server/accounts/sync.ts
🧰 Additional context used
🧠 Learnings (1)
packages/desktop-client/src/components/banksync/EditSyncAccount.tsx (1)
Learnt from: matt-fidd
PR: actualbudget/actual#4253
File: packages/desktop-client/src/components/banksync/EditSyncAccount.tsx:154-160
Timestamp: 2025-03-12T13:10:05.044Z
Learning: In EditSyncAccount.tsx, mappings state is initialized with defaultMappings (containing both 'payment' and 'deposit' directions) if no saved mappings exist, so direction maps are guaranteed to exist.
🔇 Additional comments (7)
packages/loot-core/src/types/prefs.d.ts (1)

35-35: New preference type looks good.

The added preference type for reimporting deleted transactions follows the established naming pattern and is appropriately positioned with other sync-related preferences.

packages/desktop-client/src/components/banksync/EditSyncAccount.tsx (3)

125-127: New preference declaration looks good.

This follows the established pattern for synced preferences in this component, setting the default value to true which aligns with the current system behavior.


137-139: State initialization is consistent with other preferences.

The state variable is properly initialized and transformed from string to boolean, following the pattern used for other similar preferences.


177-177: Preference saving implementation looks good.

The implementation correctly saves the preference value when the user clicks the Save button.

packages/loot-core/src/server/accounts/sync.test.ts (3)

3-3: Added import for SyncedPrefs type.

Good addition for type safety in the tests.


127-148: Well-structured test for disabled reimporting.

This test case effectively verifies that when the reimport preference is disabled, deleted transactions are not reimported a second time. The implementation includes:

  1. Proper setup of the test database and preference
  2. Good use of TypeScript's satisfies operator for type safety
  3. Clear assertions that validate the expected behavior

150-168: Good test coverage for default reimporting behavior.

This test effectively verifies the default behavior where deleted transactions are reimported. The structure is consistent with the first test but verifies the opposite behavior.

The tests together provide complete coverage of the feature's behavior under different preference settings.

youngcw
youngcw previously approved these changes Mar 17, 2025
Copy link
Member

@youngcw youngcw left a comment

Choose a reason for hiding this comment

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

Tested with a blank transaction that I get and it is working right.

And since its opt-in it seems good to me.

checked={reimportDeleted}
onChange={() => setReimportDeleted(!reimportDeleted)}
>
<Trans>Reimport deleted transactions</Trans>
Copy link
Member

Choose a reason for hiding this comment

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

💬 suggestion: ‏would you mind also adding a <Tooltip> here explaining what this option does?

Something along the lines of..

By default imported transactions that you delete will be re-imported with the next bank sync operation. To disable this behaviour - untick this box.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point!

image

@alecbakholdin alecbakholdin force-pushed the bank-sync-reimporting-deleted-transactions branch from dfce669 to e78e476 Compare March 18, 2025 15:05
Copy link
Member

@MatissJanis MatissJanis left a comment

Choose a reason for hiding this comment

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

Great addition; thanks!

@youngcw youngcw merged commit eb5944b into actualbudget:master Mar 18, 2025
21 checks passed
luisbeqja pushed a commit to luisbeqja/actual_ai_analysis that referenced this pull request Mar 21, 2025
* matchTransactions imported_id query checks for deleted transactions

* added release notes

* removed stray import

* Added configuration option to control reimporting deleted transactions

* Updated release notes

* Unused import

* Typo

* Linting errors

* Fixed Checkbox id to match what it's for

* Added tooltip for the checkbox

---------

Co-authored-by: Alec Bakholdin <abakho@icims.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants