Skip to content
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

Fixes try_add_state in actor state manger #756

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dapr/actor/runtime/state_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async def try_add_state(self, state_name: str, value: T) -> bool:
existed = await self._actor.runtime_ctx.state_provider.contains_state(
self._type_name, self._actor.id.id, state_name
)
if not existed:
if existed:
return False

state_change_tracker[state_name] = StateMetadata(value, StateChangeKind.add)
Expand Down
16 changes: 15 additions & 1 deletion tests/actor/test_state_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def setUp(self):

@mock.patch(
'tests.actor.fake_client.FakeDaprActorClient.get_state',
new=_async_mock(return_value=base64.b64encode(b'"value1"')),
new=_async_mock(),
)
@mock.patch(
'tests.actor.fake_client.FakeDaprActorClient.save_state_transactionally', new=_async_mock()
Expand All @@ -67,6 +67,20 @@ def test_add_state(self):
added = _run(state_manager.try_add_state('state1', 'value1'))
self.assertFalse(added)

@mock.patch(
'tests.actor.fake_client.FakeDaprActorClient.get_state',
new=_async_mock(return_value=base64.b64encode(b'"value1"')),
)
@mock.patch(
'tests.actor.fake_client.FakeDaprActorClient.save_state_transactionally', new=_async_mock()
)
def test_add_state_with_existing_state(self):
state_manager = ActorStateManager(self._fake_actor)

# Add first 'state1'
added = _run(state_manager.try_add_state('state1', 'value1'))
self.assertFalse(added)

@mock.patch('tests.actor.fake_client.FakeDaprActorClient.get_state', new=_async_mock())
def test_get_state_for_no_state(self):
state_manager = ActorStateManager(self._fake_actor)
Expand Down
Loading