From b945395d55d6b5819b1e6327e1c44e7a776f8471 Mon Sep 17 00:00:00 2001 From: vesp Date: Mon, 5 Jan 2026 11:50:36 +0100 Subject: [PATCH] Fix history entry deletion bug with unique IDs --- src/history_manager.py | 10 +++------- src/models.py | 9 +++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/history_manager.py b/src/history_manager.py index cd8b22f..f8f584c 100644 --- a/src/history_manager.py +++ b/src/history_manager.py @@ -83,14 +83,10 @@ class HistoryManager: self.save_history(entries) def delete_entry(self, entry: HistoryEntry): - """Delete a specific entry from history.""" + """Delete a specific entry from history by ID.""" entries = self.load_history() - # Filter out the entry by comparing timestamps and URLs - entries = [e for e in entries if not ( - e.timestamp == entry.timestamp and - e.request.url == entry.request.url and - e.request.method == entry.request.method - )] + # Filter out the entry by comparing unique IDs + entries = [e for e in entries if e.id != entry.id] self.save_history(entries) def clear_history(self): diff --git a/src/models.py b/src/models.py index 06d6532..62c8772 100644 --- a/src/models.py +++ b/src/models.py @@ -69,10 +69,18 @@ class HistoryEntry: request: HttpRequest response: Optional[HttpResponse] error: Optional[str] # Error message if request failed + id: str = None # Unique identifier for the entry + + def __post_init__(self): + """Generate UUID if id not provided.""" + if self.id is None: + import uuid + self.id = str(uuid.uuid4()) def to_dict(self): """Convert to dictionary for JSON serialization.""" return { + 'id': self.id, 'timestamp': self.timestamp, 'request': self.request.to_dict(), 'response': self.response.to_dict() if self.response else None, @@ -83,6 +91,7 @@ class HistoryEntry: def from_dict(cls, data): """Create instance from dictionary.""" return cls( + id=data.get('id'), # Backwards compatible - will generate if missing timestamp=data['timestamp'], request=HttpRequest.from_dict(data['request']), response=HttpResponse.from_dict(data['response']) if data.get('response') else None,