mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Fix tags getting removed after / during bank sync (#634)
* fix: Preserve transaction tags during rule application When rules set tags, they now ADD to existing tags instead of replacing them. This fixes issue #518 where tags were being removed during bank sync. The root cause was that SetTransactionTags called enrich_attribute with just the single tag from the rule, which replaced all existing tags. Now it merges the new tag with existing tags using .uniq to prevent duplicates. This preserves: - User-applied tags that shouldn't be overwritten by rules - Tags from other rules when multiple rules match the same transaction - Tags set during previous syncs * fix: Add nil guard for tag in SetTransactionTags Return early with 0 if the tag is not found, preventing NoMethodError when find_by_id returns nil. This matches the pattern used in SetTransactionMerchant. --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ class Rule::ActionExecutor::SetTransactionTags < Rule::ActionExecutor
|
||||
|
||||
def execute(transaction_scope, value: nil, ignore_attribute_locks: false, rule_run: nil)
|
||||
tag = family.tags.find_by_id(value)
|
||||
return 0 unless tag
|
||||
|
||||
scope = transaction_scope
|
||||
|
||||
@@ -17,9 +18,14 @@ class Rule::ActionExecutor::SetTransactionTags < Rule::ActionExecutor
|
||||
end
|
||||
|
||||
count_modified_resources(scope) do |txn|
|
||||
# Merge the new tag with existing tags instead of replacing them
|
||||
# This preserves tags set by users or other rules
|
||||
existing_tag_ids = txn.tag_ids || []
|
||||
merged_tag_ids = (existing_tag_ids + [ tag.id ]).uniq
|
||||
|
||||
txn.enrich_attribute(
|
||||
:tag_ids,
|
||||
[ tag.id ],
|
||||
merged_tag_ids,
|
||||
source: "rule"
|
||||
)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user