Skip to content

Commit

Permalink
remove lock changes
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Jun 19, 2024
1 parent c6ce18a commit a6aaa61
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 12 deletions.
3 changes: 2 additions & 1 deletion superset/commands/key_value/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.

import logging
from datetime import datetime
from typing import Any, Optional, Union
from uuid import UUID

Expand Down Expand Up @@ -66,6 +67,6 @@ def validate(self) -> None:
def get(self) -> Optional[Any]:
filter_ = get_filter(self.resource, self.key)
entry = db.session.query(KeyValueEntry).filter_by(**filter_).first()
if entry and not entry.is_expired():
if entry and (entry.expires_on is None or entry.expires_on > datetime.now()):
return self.codec.decode(entry.value)
return None
5 changes: 0 additions & 5 deletions superset/key_value/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from datetime import datetime

from flask_appbuilder import Model
from sqlalchemy import Column, DateTime, ForeignKey, Integer, LargeBinary, String
from sqlalchemy.orm import relationship
Expand All @@ -40,6 +38,3 @@ class KeyValueEntry(AuditMixinNullable, ImportExportMixin, Model):
changed_by_fk = Column(Integer, ForeignKey("ab_user.id"), nullable=True)
created_by = relationship(security_manager.user_model, foreign_keys=[created_by_fk])
changed_by = relationship(security_manager.user_model, foreign_keys=[changed_by_fk])

def is_expired(self) -> bool:
return self.expires_on is not None and self.expires_on <= datetime.now()
2 changes: 1 addition & 1 deletion superset/utils/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def dumps( # pylint: disable=too-many-arguments
cls=cls,
)
except UnicodeDecodeError:
results_string = simplejson.dumps(
results_string = simplejson.dumps( # type: ignore[call-overload]
obj,
default=default,
allow_nan=allow_nan,
Expand Down
6 changes: 1 addition & 5 deletions superset/utils/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ def sort(obj: T) -> T:
return json.dumps(params)


def get_key(namespace: str, **kwargs: Any) -> uuid.UUID:
return uuid.uuid5(uuid.uuid5(uuid.NAMESPACE_DNS, namespace), serialize(kwargs))


@contextmanager
def KeyValueDistributedLock( # pylint: disable=invalid-name
namespace: str,
Expand All @@ -82,7 +78,7 @@ def KeyValueDistributedLock( # pylint: disable=invalid-name
from superset.commands.key_value.delete import DeleteKeyValueCommand
from superset.commands.key_value.delete_expired import DeleteExpiredKeyValueCommand

key = get_key(namespace, **kwargs)
key = uuid.uuid5(uuid.uuid5(uuid.NAMESPACE_DNS, namespace), serialize(kwargs))
logger.debug("Acquiring lock on namespace %s for key %s", namespace, key)
try:
DeleteExpiredKeyValueCommand(resource=KeyValueResource.LOCK).run()
Expand Down

0 comments on commit a6aaa61

Please sign in to comment.