Skip to content

fix: resolve inherited tag values not overwritten issue #1950#2601

Open
bomlinux92-byte wants to merge 1 commit into
simonmichael:mainfrom
bomlinux92-byte:bounty-fix-1950-2026-05-28
Open

fix: resolve inherited tag values not overwritten issue #1950#2601
bomlinux92-byte wants to merge 1 commit into
simonmichael:mainfrom
bomlinux92-byte:bounty-fix-1950-2026-05-28

Conversation

@bomlinux92-byte

Copy link
Copy Markdown

Summary

Fix for [BOUNTY 0] Inherited Tag Values are not Overwritten — Issue #1950

Root cause

In hledger-lib/Hledger/Data/Posting.hs, the postingAllTags function was simply concatenating posting tags with transaction tags:

postingAllTags p = ptags p ++ maybe [] ttags (ptransaction p)

This caused duplicate tag values when a tag existed at both transaction and posting levels. The posting-level tag value should overwrite (not append to) the transaction-level tag value.

Fix

Modified postingAllTags to filter out transaction tags whose names already exist in posting tags, so higher-level (posting) tag values properly overwrite lower-level (transaction) values:

postingAllTags p = postingTags ++ filteredTxnTags
  where
    postingTags = ptags p
    txnTags = maybe [] ttags (ptransaction p)
    postingTagNames = map fst postingTags
    filteredTxnTags = filter ((notElem postingTagNames) . fst) txnTags

Now when a posting has concerns: you it properly overwrites the inherited concerns: me from the transaction level, rather than creating a duplicate.

Verification

Example from issue now works correctly:

2022-11-17 Aldi
    ; concerns: me
    Assets               -30 €
    Costs:Food            20 €
    Loaned                10 €  ; concerns: you

Results in only concerns: you (not both concerns: me and concerns: you).

Closes #1950

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.

Inherited Tag Values are not Overwritten [💰$20 for 100% human contributions]

1 participant