Skip to content

Commit

Permalink
🐛 Fixes replace operation in projects and uninitialized variable in h…
Browse files Browse the repository at this point in the history
…ealth-check (#4469)
  • Loading branch information
pcrespov authored Jul 6, 2023
1 parent e3b40b4 commit afc1eb0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 5 additions & 5 deletions packages/service-library/src/servicelib/aiohttp/incidents.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Callable, Generic, List, Optional, TypeVar
from typing import Any, Callable, Generic, TypeVar

import attr

Expand All @@ -20,9 +20,9 @@ class LimitedOrderedStack(Generic[ItemT]):
"""

max_size: int = 100
order_by: Optional[Callable[[ItemT], Any]] = None
order_by: Callable[[ItemT], Any] | None = None

_items: List[ItemT] = attr.ib(init=False, default=attr.Factory(list))
_items: list[ItemT] = attr.ib(init=False, default=attr.Factory(list))
_hits: int = attr.ib(init=False, default=0)

def __len__(self) -> int:
Expand All @@ -38,13 +38,13 @@ def hits(self) -> int:
return self._hits

@property
def max_item(self) -> Optional[ItemT]:
def max_item(self) -> ItemT | None:
if self._items:
return self._items[0]
return None

@property
def min_item(self) -> Optional[ItemT]:
def min_item(self) -> ItemT | None:
if self._items:
return self._items[-1]
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

class IncidentsRegistry(LimitedOrderedStack[SlowCallback]):
def max_delay(self) -> float:
delay: float = self.max_item.delay_secs or 0.0
delay: float = 0.0
if self.max_item:
delay = self.max_item.delay_secs
return delay


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,10 @@ async def replace_project(request: web.Request):

try:
new_project = await request.json()
# NOTE: this is a temporary fix until proper Model is introduced in ProjectReplace
# Prune state field (just in case)
new_project.pop("state", None)
new_project.pop("permalink", None)

except json.JSONDecodeError as exc:
raise web.HTTPBadRequest(reason="Invalid request body") from exc
Expand Down

0 comments on commit afc1eb0

Please sign in to comment.