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 replace operation in projects and uninitialized variable in health-check #4469

Merged
merged 2 commits into from
Jul 6, 2023
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
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