Skip to content

Commit

Permalink
fix: prevent api calls when printing bound models (#305)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jooola committed Sep 26, 2023
1 parent 5a73075 commit c1de7ef
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions hcloud/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,9 @@ def reload(self) -> None:
bound_model = self._client.get_by_id(self.data_model.id)
self.data_model = bound_model.data_model
self.complete = True

def __repr__(self) -> str:
# Override and reset hcloud.core.domain.BaseDomain.__repr__ method for bound
# models, as they will generate a lot of API call trying to print all the fields
# of the model.
return object.__repr__(self)

0 comments on commit c1de7ef

Please sign in to comment.