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