Skip to content

Commit

Permalink
handle not existing attr
Browse files Browse the repository at this point in the history
  • Loading branch information
daroczig committed Dec 27, 2023
1 parent 75d48ea commit 786e7be
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sc_crawler/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ class Vendor(BaseModel):
@computed_field
@property
def datacenters(self) -> int:
return len(self._datacenters)
if hasattr(self, "_datacenters"):
return len(self._datacenters)
else:
return 0

@computed_field
@property
def zones(self) -> int:
return sum([datacenter.zones for datacenter in self._datacenters])
if hasattr(self, "_datacenters"):
return sum([datacenter.zones for datacenter in self._datacenters])
else:
return 0

# private attributes
_methods: ImportString[ModuleType] = PrivateAttr()
Expand Down

0 comments on commit 786e7be

Please sign in to comment.