From 29a697a8e78488946ed3b040163d26288809216a Mon Sep 17 00:00:00 2001 From: Andy Date: Sun, 8 Feb 2026 20:04:22 -0700 Subject: [PATCH] fix(tracks): close temp session and improve path type error --- unshackle/core/tracks/attachment.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/unshackle/core/tracks/attachment.py b/unshackle/core/tracks/attachment.py index 48f1e54..9caacab 100644 --- a/unshackle/core/tracks/attachment.py +++ b/unshackle/core/tracks/attachment.py @@ -65,9 +65,13 @@ class Attachment: path = None else: try: - session = session or requests.Session() - response = session.get(url, stream=True) - response.raise_for_status() + if session is None: + with requests.Session() as session: + response = session.get(url, stream=True) + response.raise_for_status() + else: + response = session.get(url, stream=True) + response.raise_for_status() config.directories.temp.mkdir(parents=True, exist_ok=True) download_path.parent.mkdir(parents=True, exist_ok=True) @@ -80,7 +84,9 @@ class Attachment: raise ValueError(f"Failed to download attachment from URL: {e}") if path is not None and not isinstance(path, (str, Path)): - raise ValueError("The attachment path must be provided.") + raise ValueError( + f"Invalid attachment path type: expected str or Path, got {type(path).__name__}." + ) if path is not None: path = Path(path)