Fix history entry deletion bug with unique IDs
This commit is contained in:
parent
5555601bcf
commit
1f49ef288f
@ -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):
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user