Skip to content

fix(dl): compare queued paths as strings so same-name documents get their id appended - #407

Open
leonlowitzki wants to merge 1 commit into
pytr-org:masterfrom
leonlowitzki:fix/dl-same-name-collision
Open

leonlowitzki wants to merge 1 commit into
pytr-org:masterfrom
leonlowitzki:fix/dl-same-name-collision

Conversation

@leonlowitzki

Copy link
Copy Markdown

Two orders of the same instrument executed within the same minute end up as one PDF: the later download overwrites the earlier one.

Cause

dl_doc already handles this case: if the computed path is already queued, it appends the document id (dl.py:455-462). But the check never fires:

self.filepaths: List[str] = []           # holds str
...
if filepath in self.filepaths:            # filepath is a Path → never equal to a str
...
self.filepaths.append(str(filepath))

Path("a.pdf") in ["a.pdf"] is False, so both documents are queued under the same path and the second write wins.

Real-world case

Two limit buys of the same stock, executed 27 seconds apart within one minute. Both render to Trades/<date> <HH:MM> Abrechnung - <name> - Limit-Buy-Order.pdf; only the later settlement survived. Same for Auftragsbestätigung and Kosteninformation.

Fix

Compare as strings (two lines). The second document now lands at … - Limit-Buy-Order (<doc id>).pdf, which is what the existing code intended.

Test

test_dl_paths_same_minute_same_title passes the Abrechnung from buy_new.json and a copy with another id through dl_doc with the same title and minute. It fails on master (both get the same path) and passes with the fix. Full suite: 285 passed; ruff check and ruff format --check clean.

Scope

This fixes collisions within one run only. If the first document was downloaded in an earlier run, the second still hits filepath.is_file() and is skipped. #398 (recognise documents by id, for #391) addresses the cross-run side; the two changes don't overlap.

…heir id appended

self.filepaths holds str, but the duplicate check tested a Path against it,
which never matches. Two orders of one instrument executed within the same
minute therefore rendered to one file name and the later download overwrote
the earlier one.
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.

1 participant