Skip to content

Prevent frontend documents/ crash from multiple doc refs - #2283

Closed
cvaske wants to merge 3 commits into
beancount:mainfrom
cvaske:cv/issue-2281-doc-dupes
Closed

cvaske wants to merge 3 commits into
beancount:mainfrom
cvaske:cv/issue-2281-doc-dupes

Conversation

@cvaske

@cvaske cvaske commented May 17, 2026 •

Copy link
Copy Markdown
Contributor

If a document filename is encountered multiple times, from transaction metadata and/or being auto-found via an options directive, Svelte code would cause a UI error without displaying any data. Fixes #2281

Change summary:

  • src/fava/json_api.py — get_documents() now deduplicates by filename, preferring explicit directives over auto-discovered ones
  • frontend/src/reports/documents/Table.svelte — Svelte {#each} key changed from doc.filename to doc.entry_hash
  • tests/test_json_api.py — Two new tests: one for explicit + auto-discovered dedup, one for two explicit directives

If a document filename is encountered multiple times, from transaction
metadata and/or being auto-found via an `options` directive, Svelte
code would cause a UI error without displaying any data. This patch
prevents the crash.

Change summary:

- `src/fava/json_api.py` — `get_documents()` now deduplicates by
  filename, preferring explicit directives over auto-discovered ones

- `frontend/src/reports/documents/Table.svelte` — Svelte `{#each}` key
  changed from `doc.filename` to `doc.entry_hash`

- `tests/test_json_api.py` — Two new tests: one for explicit +
  auto-discovered dedup, one for two explicit directives
@cvaske
cvaske force-pushed the cv/issue-2281-doc-dupes branch from 3c0a73d to bb09abf Compare May 17, 2026 22:00
@cvaske cvaske changed the title Prevent frontend documents/ crash from multiple doc refs WIP: Prevent frontend documents/ crash from multiple doc refs May 17, 2026
@cvaske
cvaske marked this pull request as draft May 17, 2026 22:02
@cvaske cvaske changed the title WIP: Prevent frontend documents/ crash from multiple doc refs Prevent frontend documents/ crash from multiple doc refs May 17, 2026
@cvaske
cvaske marked this pull request as ready for review May 17, 2026 23:26
</thead>
<tbody>
{#each sorted_documents as doc (doc.filename)}
{#each sorted_documents as doc (doc.entry_hash)}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this work? Wouldn't duplicate documents also not have the same entry hash?

@cvaske cvaske May 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This works for the test case in #2281, which is not surprising because the API change below deduplicates the file.

Moreover, if the API level changes below are removed, then the API returns the duplicate files, the entry_hashes are different, and the display continues to work, even though they have the same filename. I haven't looked deep enough into the beancount repo to find out what precisely gets hashed from the objects.

@yagebu

yagebu commented May 29, 2026

Copy link
Copy Markdown
Member

I went with just showing the duplicates in #2290

@yagebu yagebu closed this May 29, 2026
@cvaske
cvaske deleted the cv/issue-2281-doc-dupes branch July 21, 2026 20:57
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.

Documents page crashes with each_key_duplicate on duplicate Document directives

2 participants