Fix history entry deletion bug with unique IDs
This commit is contained in:
parent
ad00f0f60a
commit
b945395d55
@ -83,14 +83,10 @@ class HistoryManager:
|
|||||||
self.save_history(entries)
|
self.save_history(entries)
|
||||||
|
|
||||||
def delete_entry(self, entry: HistoryEntry):
|
def delete_entry(self, entry: HistoryEntry):
|
||||||
"""Delete a specific entry from history."""
|
"""Delete a specific entry from history by ID."""
|
||||||
entries = self.load_history()
|
entries = self.load_history()
|
||||||
# Filter out the entry by comparing timestamps and URLs
|
# Filter out the entry by comparing unique IDs
|
||||||
entries = [e for e in entries if not (
|
entries = [e for e in entries if e.id != entry.id]
|
||||||
e.timestamp == entry.timestamp and
|
|
||||||
e.request.url == entry.request.url and
|
|
||||||
e.request.method == entry.request.method
|
|
||||||
)]
|
|
||||||
self.save_history(entries)
|
self.save_history(entries)
|
||||||
|
|
||||||
def clear_history(self):
|
def clear_history(self):
|
||||||
|
|||||||
@ -69,10 +69,18 @@ class HistoryEntry:
|
|||||||
request: HttpRequest
|
request: HttpRequest
|
||||||
response: Optional[HttpResponse]
|
response: Optional[HttpResponse]
|
||||||
error: Optional[str] # Error message if request failed
|
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):
|
def to_dict(self):
|
||||||
"""Convert to dictionary for JSON serialization."""
|
"""Convert to dictionary for JSON serialization."""
|
||||||
return {
|
return {
|
||||||
|
'id': self.id,
|
||||||
'timestamp': self.timestamp,
|
'timestamp': self.timestamp,
|
||||||
'request': self.request.to_dict(),
|
'request': self.request.to_dict(),
|
||||||
'response': self.response.to_dict() if self.response else None,
|
'response': self.response.to_dict() if self.response else None,
|
||||||
@ -83,6 +91,7 @@ class HistoryEntry:
|
|||||||
def from_dict(cls, data):
|
def from_dict(cls, data):
|
||||||
"""Create instance from dictionary."""
|
"""Create instance from dictionary."""
|
||||||
return cls(
|
return cls(
|
||||||
|
id=data.get('id'), # Backwards compatible - will generate if missing
|
||||||
timestamp=data['timestamp'],
|
timestamp=data['timestamp'],
|
||||||
request=HttpRequest.from_dict(data['request']),
|
request=HttpRequest.from_dict(data['request']),
|
||||||
response=HttpResponse.from_dict(data['response']) if data.get('response') else None,
|
response=HttpResponse.from_dict(data['response']) if data.get('response') else None,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user