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:
Alexander Hess 2026-12-01 22:34:16 +01:00
commit 7d53abc057
Signed by: alexander
GPG key ID: B46EDB4DFC26805D
3 changed files with 8 additions and 7 deletions

View file

@ -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(

View file

@ -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

View file

@ -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})>"