From 329dc1faac480128734e709aba7cd114392cdcd9 Mon Sep 17 00:00:00 2001 From: Leon Lowitzki Date: Tue, 13 Oct 2026 22:53:36 +0200 Subject: [PATCH] fix(dl): compare queued paths as strings so same-name documents get their 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. --- pytr/dl.py | 4 ++-- tests/test_dl_paths.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pytr/dl.py b/pytr/dl.py index fd41868a..88a61abd 100644 --- a/pytr/dl.py +++ b/pytr/dl.py @@ -452,9 +452,9 @@ def dl_doc(self, doc, titleText, subfolder, doc_date, subtitle="", subdir_overri filepath = sanitize_filepath(filepath, "_", "auto") filepath_with_doc_id = sanitize_filepath(filepath_with_doc_id, "_", "auto") - if filepath in self.filepaths: + if str(filepath) in self.filepaths: self.log.debug(f"File {filepath} already in queue. Append document id {doc_id}...") - if filepath_with_doc_id in self.filepaths: + if str(filepath_with_doc_id) in self.filepaths: self.log.debug(f"File {filepath_with_doc_id} already in queue. Skipping...") return else: diff --git a/tests/test_dl_paths.py b/tests/test_dl_paths.py index a6c424fa..4e05972a 100644 --- a/tests/test_dl_paths.py +++ b/tests/test_dl_paths.py @@ -7,6 +7,7 @@ import json import logging +from datetime import datetime from pathlib import Path import pytest @@ -392,3 +393,15 @@ def collect_paths(fixture_name: str, tmp_path: Path) -> list[str]: @pytest.mark.parametrize("case", test_data, ids=[c["filename"] for c in test_data]) def test_dl_paths(case, tmp_path): assert collect_paths(case["filename"], tmp_path) == case["paths"] + + +def test_dl_paths_same_minute_same_title(tmp_path): + """Two documents rendering to the same name (minute precision) must not share a file.""" + dl = make_dl(tmp_path) + with open(EVENTS_DIR / "buy_new.json", encoding="utf-8") as f: + doc = json.load(f)["details"]["sections"][-1]["data"][0] + other = {**doc, "id": "other-id"} + title, when = "Abrechnung - NVIDIA - Kauforder", datetime(2025, 10, 10, 19, 29) + dl.dl_doc(doc, title, "Trades", when) + dl.dl_doc(other, title, "Trades", when) + assert other["local_filepath"].endswith(" (other-id).pdf")