Skip to content

fix: resolve bounty issue #1950 - posting tags now override inherited txn tags#2597

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

fix: resolve bounty issue #1950 - posting tags now override inherited txn tags#2597
bomlinux92-byte wants to merge 1 commit into
simonmichael:mainfrom
bomlinux92-byte:bounty-fix-1950-2026-05-19

Conversation

@bomlinux92-byte

Copy link
Copy Markdown

Summary

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

Root cause

When a posting had a tag with the same name as an inherited transaction-level tag (e.g., concerns: me on transaction, concerns: you on posting), the posting's tag value should overwrite the inherited one. However, postingAllTags was doing a simple concatenation: ptags p ++ txnTags, which meant both values were retained and matched by tag queries.

Fix

Modified postingAllTags in hledger-lib/Hledger/Data/Posting.hs to filter out transaction-level tags whose names conflict with explicitly-set posting tags:

postingAllTags :: Posting -> [Tag]
postingAllTags p = postingTags ++ filteredTxnTags
  where
    postingTags = ptags p
    txnTags = maybe [] ttags (ptransaction p)
    postingTagNames = map fst postingTags
    filteredTxnTags = filter ((`notElem` postingTagNames) . fst) txnTags

This ensures posting-level tags take precedence over inherited transaction tags with the same name, and tag queries like tag:concerns=me only match postings that genuinely have that effective tag value.

Testing

The existing test case a tag match on a posting also sees inherited tags in Query.hs continues to pass (inherited tags without conflicts are still visible), and the fix properly handles the overwrite case.

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