Review the ORM models and align the live database with them #16
6 changed files with 8 additions and 7 deletions
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.
commit
7d53abc057
|
|
@ -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})>"
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class TestSpecialMethods:
|
|||
"""`ReplayedOrder` has a non-literal text representation."""
|
||||
result = repr(replayed_order)
|
||||
|
||||
assert result == f"<ReplayedOrder(#{replayed_order.actual.id})>"
|
||||
assert result == f"<ReplayedOrder(#{replayed_order.actual_order_id})>"
|
||||
|
||||
|
||||
@pytest.mark.db
|
||||
|
|
|
|||
|
|
@ -13,5 +13,5 @@ class TestSpecialMethods:
|
|||
result = repr(simulation)
|
||||
|
||||
assert result.startswith("<ReplaySimulation(")
|
||||
assert simulation.city.name in result
|
||||
assert f"city #{simulation.city_id}" in result
|
||||
assert simulation.strategy in result
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class TestSpecialMethods:
|
|||
|
||||
assert (
|
||||
result
|
||||
== f"<Forecast: {forecast.prediction} for pixel ({forecast.pixel.n_x}|{forecast.pixel.n_y}) at {forecast.start_at}>" # noqa:E501
|
||||
== f"<Forecast: {forecast.prediction} for pixel #{forecast.pixel_id} at {forecast.start_at}>" # noqa:E501
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue