chore: use json codec for key value lock (#29285)

This commit is contained in:
Ville Brofeldt 2024-06-19 01:33:47 +03:00 committed by GitHub
parent 796726376a
commit 9f70697046
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -26,7 +26,7 @@ from typing import Any, cast, TypeVar, Union
from superset.exceptions import CreateKeyValueDistributedLockFailedException
from superset.key_value.exceptions import KeyValueCreateFailedError
from superset.key_value.types import KeyValueResource, PickleKeyValueCodec
from superset.key_value.types import JsonKeyValueCodec, KeyValueResource
from superset.utils import json
LOCK_EXPIRATION = timedelta(seconds=30)
@ -83,7 +83,7 @@ def KeyValueDistributedLock( # pylint: disable=invalid-name
DeleteExpiredKeyValueCommand(resource=KeyValueResource.LOCK).run()
CreateKeyValueCommand(
resource=KeyValueResource.LOCK,
codec=PickleKeyValueCodec(),
codec=JsonKeyValueCodec(),
key=key,
value=True,
expires_on=datetime.now() + LOCK_EXPIRATION,

View File

@ -42,7 +42,7 @@ def test_KeyValueDistributedLock_happy_path(mocker: MockerFixture) -> None:
DeleteExpiredKeyValueCommand = mocker.patch(
"superset.commands.key_value.delete_expired.DeleteExpiredKeyValueCommand"
)
PickleKeyValueCodec = mocker.patch("superset.utils.lock.PickleKeyValueCodec")
JsonKeyValueCodec = mocker.patch("superset.utils.lock.JsonKeyValueCodec")
with freeze_time("2024-01-01"):
with KeyValueDistributedLock("ns", a=1, b=2) as key:
@ -51,7 +51,7 @@ def test_KeyValueDistributedLock_happy_path(mocker: MockerFixture) -> None:
)
CreateKeyValueCommand.assert_called_with(
resource=KeyValueResource.LOCK,
codec=PickleKeyValueCodec(),
codec=JsonKeyValueCodec(),
key=key,
value=True,
expires_on=datetime(2024, 1, 1, 0, 0, 30),