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

Fix rules not checking "category is nothing" when reconciling #3572

Merged

Conversation

davidmartos96
Copy link
Contributor

@davidmartos96 davidmartos96 commented Oct 4, 2024

Fixes #2540

The call to runRules passes a transaction that doesn't include a category (aka undefined), so the rule checking "category is nothing" doesn't work.
My solution is to provide a category or null in both normalizeBankSyncTransactions and normalizeTransactions

This is my first dig into the source of the project, but hopefully this solution or similar is valid.

@actual-github-bot actual-github-bot bot changed the title Fix rules not checking "category is nothing" when reconciling [WIP] Fix rules not checking "category is nothing" when reconciling Oct 4, 2024
Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

Walkthrough

The changes in this pull request primarily involve modifications to the sync.ts file within the loot-core package. The updates focus on enhancing transaction handling by introducing a new category property in several functions, including normalizeTransactions, normalizeBankSyncTransactions, reconcileTransactions, and addTransactions. This property defaults to null if not specified, ensuring consistent management of transaction categories during normalization and reconciliation processes.

Assessment against linked issues

Objective Addressed Explanation
Ensure "Category is (nothing)" rule is respected (#2540)

Possibly related PRs

  • fix creating rule from transaction #3539: The changes in the Account.tsx component involve handling transaction rules, which may relate to the new category property introduced in the main PR, as both involve transaction management and properties associated with transactions.

Suggested labels

:sparkles: Merged


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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 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

netlify bot commented Oct 4, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit b357a7f
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/6706b85e4ab6660008020aa5
😎 Deploy Preview https://deploy-preview-3572.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

@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 and nitpick comments (2)
packages/loot-core/src/server/accounts/sync.ts (2)

299-299: LGTM: Consistent handling of category for bank sync transactions

This change ensures that bank sync transactions include the category property, maintaining consistency with regular transactions.

For consistency with the normalizeTransactions function, consider moving this assignment to a separate line:

-        category: trans.category || null,
+        category: null,
+      },
+    });
+    normalized[normalized.length - 1].trans.category = trans.category || null;

This change would make it easier to add any future normalization logic for the category property.


Line range hint 380-380: LGTM: Proper handling of category during reconciliation

This change ensures that the category is included when updating existing transactions during reconciliation. The logic correctly prioritizes the existing category, then the new transaction's category, and finally defaults to null.

For improved clarity, consider using a ternary operator:

-        category: existing.category || trans.category || null,
+        category: existing.category ? existing.category : (trans.category || null),

This change makes it more explicit that we're prioritizing the existing category over the new one.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a28fb93 and 709698c.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/3572.md is excluded by !**/*.md
📒 Files selected for processing (1)
  • packages/loot-core/src/server/accounts/sync.ts (2 hunks)
🔇 Additional comments (3)
packages/loot-core/src/server/accounts/sync.ts (3)

241-242: LGTM: Ensures category is always set

This change ensures that all transactions have a category property, even if it's null. This addresses the core issue where rules were not checking 'category is nothing' when reconciling transactions.


Line range hint 724-726: LGTM: No changes needed for addTransactions

The addTransactions function doesn't require direct changes related to the category property. The category is already being handled correctly in the normalizeTransactions function, which is called at the beginning of addTransactions. The existing logic preserves the category property when creating the finalTransaction object.


Line range hint 1-1004: Overall assessment: Changes effectively address the PR objective

The modifications in this file consistently handle the category property across different functions involved in transaction synchronization and normalization. These changes effectively address the PR objective of fixing the issue where rules were not checking 'category is nothing' when reconciling transactions.

Key improvements:

  1. normalizeTransactions: Ensures all transactions have a category property, even if it's null.
  2. normalizeBankSyncTransactions: Maintains consistency in handling the category property for bank sync transactions.
  3. reconcileTransactions: Properly includes the category when updating existing transactions during reconciliation.

The implementation is consistent and maintains backwards compatibility. These changes should resolve the issue described in the linked bug report (#2540) where the 'Category is (nothing)' rule was not being respected during account synchronization.

Copy link
Contributor

github-actions bot commented Oct 4, 2024

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
9 5.31 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/usePreviewTransactions.js 1.64 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/AppliedFilters.js 20.96 kB 0%
static/js/narrow.js 82.55 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/wide.js 224.88 kB 0%
static/js/ReportRouter.js 1.51 MB 0%
static/js/index.js 3.33 MB 0%

Copy link
Contributor

github-actions bot commented Oct 4, 2024

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 1.26 MB → 1.26 MB (+54 B) +0.00%
Changeset
File Δ Size
packages/loot-core/src/server/accounts/sync.ts 📈 +99 B (+0.40%) 24.05 kB → 24.15 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
kcab.worker.js 1.26 MB → 1.26 MB (+54 B) +0.00%

Smaller

No assets were smaller

Unchanged

No assets were unchanged

@davidmartos96 davidmartos96 changed the title [WIP] Fix rules not checking "category is nothing" when reconciling Fix rules not checking "category is nothing" when reconciling Oct 4, 2024
Copy link
Contributor

@matt-fidd matt-fidd left a comment

Choose a reason for hiding this comment

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

Thanks for this! I've added a couple of suggestions with the operators, and a minor wording tweak on the release note to make it a little clearer

upcoming-release-notes/3572.md Outdated Show resolved Hide resolved
packages/loot-core/src/server/accounts/sync.ts Outdated Show resolved Hide resolved
packages/loot-core/src/server/accounts/sync.ts Outdated Show resolved Hide resolved
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 and nitpick comments (1)
packages/loot-core/src/server/accounts/sync.ts (1)

Line range hint 1-793: Overall, the changes improve category handling, but a few points need attention.

The modifications consistently handle the new category property across different functions, addressing the PR objectives. However, consider addressing the following points:

  1. In the reconcileTransactions function, consider adding logic to preserve manually set categories that differ from imported ones.
  2. In the addTransactions function, either implement the usage of the new category parameter or remove it if it's not intended to be used.

These adjustments will further enhance the robustness and clarity of the category handling implementation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 709698c and 9dd4342.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/3572.md is excluded by !**/*.md
📒 Files selected for processing (1)
  • packages/loot-core/src/server/accounts/sync.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (4)
packages/loot-core/src/server/accounts/sync.ts (4)

241-242: LGTM! Nullish coalescing implemented as suggested.

The change ensures that trans.category is always set to either its existing value or null, addressing the issue mentioned in the PR objectives. This implementation also follows the previous review suggestion to use nullish coalescing.


299-299: LGTM! Consistent handling of category property.

The addition of the category property to bank sync transactions, with nullish coalescing to default to null, is consistent with the changes made in the normalizeTransactions function. This ensures uniform handling of the category across different transaction sources.


Line range hint 686-686: LGTM, but the new category parameter is unused.

The addition of the category parameter to the addTransactions function signature is consistent with the other changes for handling categories. However, it appears that this new parameter is not utilized within the function body.

Consider one of the following actions:

  1. Remove the category parameter if it's not intended to be used.
  2. Implement the logic to use the category parameter within the function.

To verify the usage of the category parameter, we can search for its occurrences within the addTransactions function:


Line range hint 391-391: LGTM, but consider preserving manually set categories.

The addition of the category property to the updates object ensures proper category handling during reconciliation. The fallback chain (existing category → transaction category → null) is a good approach. However, consider the following:

  1. This logic might overwrite manually set categories with imported ones.
  2. It may be beneficial to add a check to preserve manually set categories, especially if they differ from the imported category.

To verify the potential impact on manually set categories, we can check for instances where categories might be overwritten:

Copy link
Contributor

@matt-fidd matt-fidd left a comment

Choose a reason for hiding this comment

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

Thank you!

@matt-fidd matt-fidd merged commit f786bdc into actualbudget:master Oct 9, 2024
20 checks passed
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.

[Bug]: "Category is (nothing)" rule is not respected
2 participants