Avoid lazy loads in .__repr__()
`ReplaySimulation`, `ReplayedOrder`, and `Forecast` accessed relationships in their `.__repr__()`, which emits queries or fails for detached instances. They now use the foreign key columns.
This commit is contained in:
parent
1f9d0effae
commit
7d53abc057
3 changed files with 8 additions and 7 deletions
|
|
@ -184,8 +184,9 @@ class Forecast(meta.Base):
|
|||
def __repr__(self) -> str:
|
||||
"""Non-literal text representation."""
|
||||
cls = self.__class__.__name__
|
||||
pixel = f"({self.pixel.n_x}|{self.pixel.n_y})"
|
||||
return f"<{cls}: {self.prediction} for pixel {pixel} at {self.start_at}>"
|
||||
return (
|
||||
f"<{cls}: {self.prediction} for pixel #{self.pixel_id} at {self.start_at}>"
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_dataframe(
|
||||
|
|
|
|||
|
|
@ -411,7 +411,7 @@ class ReplayedOrder(meta.Base):
|
|||
|
||||
def __repr__(self) -> str:
|
||||
"""Non-literal text representation."""
|
||||
return f"<{self.__class__.__name__}(#{self.actual.id})>"
|
||||
return f"<{self.__class__.__name__}(#{self.actual_order_id})>"
|
||||
|
||||
# Convenience properties
|
||||
|
||||
|
|
|
|||
|
|
@ -63,4 +63,4 @@ class ReplaySimulation(meta.Base):
|
|||
def __repr__(self) -> str:
|
||||
"""Non-literal text representation."""
|
||||
cls = self.__class__.__name__
|
||||
return f"<{cls}({self.strategy} #{self.run} in {self.city.name})>"
|
||||
return f"<{cls}({self.strategy} #{self.run} in city #{self.city_id})>"
|
||||
|
|
|
|||
Loading…
Reference in a new issue