Skip to content

Commit

Permalink
Merge pull request #1067 from OpenChemistry/faust-mutable-defaults
Browse files Browse the repository at this point in the history
Initialize mutable values using __post__init__
  • Loading branch information
cjh1 authored Mar 19, 2024
2 parents 593661d + 6348b7c commit 089d4ed
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions backend/faust/scan_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,20 @@ class ScanStatus(faust.Record, coerce=True):
created: Optional[str] = None
uuid: Optional[str] = None
host: Optional[str] = None
paths: List[str] = []
paths: List[str] = None
# map of path to progress for receiver
progress_by_path: Dict[str, int] = {}
progress_by_path: Dict[str, int] = None
modified: Optional[datetime] = None

# We have to initialize the list and dict in __post_init__ as unlike
# pydantic, faust does not deal with mutable default values!
def __post_init__(self):
if self.paths is None:
self.paths = []

if self.progress_by_path is None:
self.progress_by_path = {}

def progress(self):
try:
return round(sum(self.progress_by_path.values()) / 4)
Expand Down

0 comments on commit 089d4ed

Please sign in to comment.