Skip to content

Commit c1de7ef

Browse files
authored
fix: prevent api calls when printing bound models (#305)
On large objects such as servers, we might generate more than 10 api calls just to print a single server object. This is because the `__repr__` method will recursively generate the `__repr__` for each bound model property and will trigger a `reload` on incomplete models to gather the information from the API.
1 parent 5a73075 commit c1de7ef

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

hcloud/core/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@ def reload(self) -> None:
9090
bound_model = self._client.get_by_id(self.data_model.id)
9191
self.data_model = bound_model.data_model
9292
self.complete = True
93+
94+
def __repr__(self) -> str:
95+
# Override and reset hcloud.core.domain.BaseDomain.__repr__ method for bound
96+
# models, as they will generate a lot of API call trying to print all the fields
97+
# of the model.
98+
return object.__repr__(self)

0 commit comments

Comments
 (0)