-
Notifications
You must be signed in to change notification settings - Fork 439
fix: raise ValueError on append to nonexistent artifact #1040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,12 +74,14 @@ def append_artifact_to_task(task: Task, event: TaskArtifactUpdateEvent) -> None: | |
| dict(new_artifact_data.metadata.items()) | ||
| ) | ||
| else: | ||
| # We received a chunk to append, but we don't have an existing artifact. | ||
| # we will ignore this chunk | ||
| logger.warning( | ||
| 'Received append=True for nonexistent artifact index %s in task %s. Ignoring chunk.', | ||
| artifact_id, | ||
| task.id, | ||
| # We received a chunk to append, but there is no existing artifact | ||
| # with this id. Silently dropping the chunk would hide a real bug | ||
| # in the caller (e.g. generating a fresh artifact_id on every | ||
| # add_artifact call instead of pinning one), so we raise. | ||
| raise ValueError( | ||
| f'append=True but no artifact with id {artifact_id!r} exists on ' | ||
| f'task {task.id!r}. Create the artifact first (append=False) ' | ||
| f'before appending to it.' | ||
| ) | ||
|
Comment on lines
+81
to
85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using raise InvalidParamsErrorReferences
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -429,6 +429,7 @@ def test_append_artifact_to_task(): | |||||
| assert len(task.artifacts[1].parts) == 1 | ||||||
|
|
||||||
| # Test appending part to a task that does not have a matching artifact | ||||||
| # raises ValueError instead of silently dropping the chunk (#1038) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| non_existing_artifact_with_parts = Artifact( | ||||||
| artifact_id='artifact-456', parts=[Part(text='Part 1')] | ||||||
| ) | ||||||
|
|
@@ -438,7 +439,9 @@ def test_append_artifact_to_task(): | |||||
| task_id='123', | ||||||
| context_id='123', | ||||||
| ) | ||||||
| append_artifact_to_task(task, append_event_5) | ||||||
| with pytest.raises(ValueError, match='append=True but no artifact with id'): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the test to assert
Suggested change
References
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| append_artifact_to_task(task, append_event_5) | ||||||
| # Artifacts unchanged — the bad chunk was not silently added | ||||||
| assert len(task.artifacts) == 2 | ||||||
| assert len(task.artifacts[0].parts) == 2 | ||||||
| assert len(task.artifacts[1].parts) == 1 | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider reframing this description. Future readers will have no context of the chunk being dropped so mentioning it seems redundant. Let's just describe current behaviour without mentioning the prior.