Fix SAWarnings #7

Merged
alexander merged 4 commits from fix-sawarnings into develop 2026-11-30 11:05:12 +01:00
2 changed files with 21 additions and 6 deletions
Showing only changes of commit ee5a372b2b - Show all commits

Link new objects from the parent

Since SQLAlchemy 2.0, only the parent's end
cascades a new object into the session'
Alexander Hess 2026-11-30 10:40:27 +01:00
Signed by: alexander
GPG key ID: B46EDB4DFC26805D

View file

@ -74,7 +74,9 @@ class Grid(meta.Base):
Returns:
grid: including `grid.pixels` with the associated `city.addresses`
"""
grid = cls(city=city, side_length=side_length)
grid = cls(side_length=side_length)
city.grids.append(grid)
# `Pixel`s grouped by `.n_x`-`.n_y` coordinates.
pixels = {}
@ -102,7 +104,9 @@ class Grid(meta.Base):
n_x, n_y = address.x // side_length, address.y // side_length
# ... and create a new `Pixel` object if necessary.
if (n_x, n_y) not in pixels:
pixels[(n_x, n_y)] = db.Pixel(grid=grid, n_x=n_x, n_y=n_y)
pixels[(n_x, n_y)] = db.Pixel(n_x=n_x, n_y=n_y)
grid.pixels.append(pixels[(n_x, n_y)])
pixel = pixels[(n_x, n_y)]
# Create an association between the `address` and `pixel`.

View file

@ -13,7 +13,11 @@ def make_address(city):
def func(**kwargs):
"""Create an `Address` object in the `city`."""
return factories.AddressFactory.build(city=city, **kwargs)
address = factories.AddressFactory.build(**kwargs)
city.addresses.append(address)
return address
return func
@ -58,7 +62,11 @@ def make_restaurant(make_address):
if address is None:
address = make_address()
return factories.RestaurantFactory.build(address=address, **kwargs)
restaurant = factories.RestaurantFactory.build(**kwargs)
address.restaurants.append(restaurant)
return restaurant
return func
@ -93,15 +101,18 @@ def make_order(make_address, make_courier, make_customer, make_restaurant):
if courier is None:
courier = make_courier()
return factory_cls.build(
order = factory_cls.build(
customer=make_customer(), # assume a unique `Customer` per order
restaurant=restaurant,
courier=courier,
pickup_address=restaurant.address, # no `Address` history
delivery_address=make_address(), # unique `Customer` => new `Address`
**kwargs,
)
restaurant.orders.append(order)
return order
return func