-
Notifications
You must be signed in to change notification settings - Fork 49
fix(states): update states by state ID only #278
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
Merged
deepthi-rao-scale
merged 4 commits into
main
from
deepthirao/agx1-319-reject-state-update-requests-when-body-task_id-mismatches
Jun 5, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0235fad
DRAFT: update states by state id only
deepthi-rao-scale 986121c
fix(states): accept legacy update parent fields
deepthi-rao-scale f4fa8c3
test(states): remove redundant update schema test
deepthi-rao-scale d4566de
chore(states): update OpenAPI spec
deepthi-rao-scale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| from fastapi import Depends | ||
|
|
||
| from src.adapters.crud_store.exceptions import ItemDoesNotExist | ||
| from src.domain.entities.states import StateEntity | ||
| from src.domain.repositories.task_state_repository import DTaskStateRepository | ||
| from src.utils.logging import make_logger | ||
|
|
@@ -58,13 +59,14 @@ async def list( | |
| order_direction=order_direction, | ||
| ) | ||
|
|
||
| async def update(self, id: str, task_id: str, state: dict[str, Any]) -> StateEntity: | ||
| async def update(self, id: str, state: dict[str, Any]) -> StateEntity: | ||
| task_state = await self.task_state_repository.get(id=id) | ||
| if task_state and task_state.task_id == task_id: | ||
| # Update the state field but preserve other fields | ||
| task_state.state = state | ||
| return await self.task_state_repository.update(task_state) | ||
|
Collaborator
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. @smoreinis any reason not having the task_id would introduce a regression?
Collaborator
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. we should be fine here, thanks for double checking |
||
| return task_state | ||
| if task_state is None: | ||
| raise ItemDoesNotExist(f"State {id} not found") | ||
|
|
||
| # Update the state field but preserve other fields. | ||
| task_state.state = state | ||
| return await self.task_state_repository.update(task_state) | ||
|
|
||
| async def delete(self, id: str) -> None: | ||
| return await self.task_state_repository.delete(id=id) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import pytest | ||
| from src.api.schemas.states import UpdateStateRequest | ||
|
|
||
| @pytest.mark.unit | ||
| def test_update_state_request_ignores_legacy_parent_identifiers(): | ||
| request = UpdateStateRequest.model_validate( | ||
| { | ||
| "state": {"status": "new"}, | ||
| "task_id": "task-1", | ||
| "agent_id": "agent-1", | ||
| } | ||
| ) | ||
|
|
||
| assert request.model_dump() == {"state": {"status": "new"}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| from unittest.mock import AsyncMock | ||
|
|
||
| import pytest | ||
| from src.adapters.crud_store.exceptions import ItemDoesNotExist | ||
| from src.domain.entities.states import StateEntity | ||
| from src.domain.repositories.task_state_repository import TaskStateRepository | ||
| from src.domain.use_cases.states_use_case import StatesUseCase | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def task_state_repository(): | ||
| repository = AsyncMock(spec=TaskStateRepository) | ||
| repository.get = AsyncMock() | ||
| repository.update = AsyncMock() | ||
| return repository | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def states_use_case(task_state_repository): | ||
| return StatesUseCase(task_state_repository=task_state_repository) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def existing_state(): | ||
| return StateEntity( | ||
| id="state-1", | ||
| task_id="task-1", | ||
| agent_id="agent-1", | ||
| state={"status": "old"}, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.unit | ||
| @pytest.mark.asyncio | ||
| class TestStatesUseCase: | ||
| async def test_update_mutates_state_by_id( | ||
| self, states_use_case, task_state_repository, existing_state | ||
| ): | ||
| task_state_repository.get.return_value = existing_state | ||
| task_state_repository.update.return_value = existing_state | ||
|
|
||
| result = await states_use_case.update( | ||
| id="state-1", | ||
| state={"status": "new"}, | ||
| ) | ||
|
|
||
| assert result is existing_state | ||
| assert result.state == {"status": "new"} | ||
| task_state_repository.get.assert_awaited_once_with(id="state-1") | ||
| task_state_repository.update.assert_awaited_once_with(existing_state) | ||
|
|
||
| async def test_update_raises_not_found_when_state_does_not_exist( | ||
| self, states_use_case, task_state_repository | ||
| ): | ||
| task_state_repository.get.return_value = None | ||
|
|
||
| with pytest.raises(ItemDoesNotExist) as exc_info: | ||
| await states_use_case.update( | ||
| id="state-1", | ||
| state={"status": "new"}, | ||
| ) | ||
|
|
||
| assert "State state-1 not found" in str(exc_info.value) | ||
| task_state_repository.get.assert_awaited_once_with(id="state-1") | ||
| task_state_repository.update.assert_not_awaited() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.