Upgrade sqlalchemy
Adapt code to prevent new warnings and errors (as of SQLAlchemy 1.4): - Overlapping foreign key columns could be set in a conflicting way => This is prevented by the application logic => Ignore the warning by setting a `overlaps` flag - Transaction already rolled back => This only happens when tests cause an `IntegrityError` on purpose => Filter away the corresponding warning in the fixture - Query returns `Row` objects and not scalars => Add genexpr to pull out `primary_id`
This commit is contained in:
parent
3bef9ca38d
commit
2d08afa309
6 changed files with 75 additions and 68 deletions
|
|
@ -58,16 +58,6 @@ class Address(meta.Base):
|
|||
|
||||
# Relationships
|
||||
city = orm.relationship('City', back_populates='addresses')
|
||||
_distances1 = orm.relationship(
|
||||
'DistanceMatrix',
|
||||
back_populates='first_address',
|
||||
foreign_keys='[DistanceMatrix.first_address_id, DistanceMatrix.city_id]',
|
||||
)
|
||||
_distances2 = orm.relationship(
|
||||
'DistanceMatrix',
|
||||
back_populates='second_address',
|
||||
foreign_keys='[DistanceMatrix.second_address_id, DistanceMatrix.city_id]',
|
||||
)
|
||||
restaurants = orm.relationship('Restaurant', back_populates='address')
|
||||
orders_picked_up = orm.relationship(
|
||||
'Order',
|
||||
|
|
|
|||
|
|
@ -89,13 +89,12 @@ class DistanceMatrix(meta.Base):
|
|||
# Relationships
|
||||
first_address = orm.relationship(
|
||||
'Address',
|
||||
back_populates='_distances1',
|
||||
foreign_keys='[DistanceMatrix.first_address_id, DistanceMatrix.city_id]',
|
||||
)
|
||||
second_address = orm.relationship(
|
||||
'Address',
|
||||
back_populates='_distances2',
|
||||
foreign_keys='[DistanceMatrix.second_address_id, DistanceMatrix.city_id]',
|
||||
overlaps='first_address',
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -67,11 +67,14 @@ class Customer(meta.Base):
|
|||
db.session.query(db.Address)
|
||||
.filter(
|
||||
db.Address.id.in_(
|
||||
db.session.query(db.Address.primary_id) # noqa:WPS221
|
||||
.join(db.Order, db.Address.id == db.Order.delivery_address_id)
|
||||
.filter(db.Order.customer_id == self.id)
|
||||
.distinct()
|
||||
.all(),
|
||||
row.primary_id
|
||||
for row in (
|
||||
db.session.query(db.Address.primary_id) # noqa:WPS221
|
||||
.join(db.Order, db.Address.id == db.Order.delivery_address_id)
|
||||
.filter(db.Order.customer_id == self.id)
|
||||
.distinct()
|
||||
.all()
|
||||
)
|
||||
),
|
||||
)
|
||||
.all()
|
||||
|
|
|
|||
|
|
@ -45,7 +45,11 @@ class Restaurant(meta.Base):
|
|||
|
||||
# Relationships
|
||||
address = orm.relationship('Address', back_populates='restaurants')
|
||||
orders = orm.relationship('Order', back_populates='restaurant')
|
||||
orders = orm.relationship(
|
||||
'Order',
|
||||
back_populates='restaurant',
|
||||
overlaps='orders_picked_up,pickup_address',
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""Non-literal text representation."""
|
||||
|
|
@ -87,11 +91,16 @@ class Restaurant(meta.Base):
|
|||
db.session.query(db.Address)
|
||||
.filter(
|
||||
db.Address.id.in_(
|
||||
db.session.query(db.Address.primary_id) # noqa:WPS221
|
||||
.join(db.Order, db.Address.id == db.Order.delivery_address_id)
|
||||
.filter(db.Order.restaurant_id == self.id)
|
||||
.distinct()
|
||||
.all(),
|
||||
row.primary_id
|
||||
for row in (
|
||||
db.session.query(db.Address.primary_id) # noqa:WPS221
|
||||
.join(
|
||||
db.Order, db.Address.id == db.Order.delivery_address_id,
|
||||
)
|
||||
.filter(db.Order.restaurant_id == self.id)
|
||||
.distinct()
|
||||
.all()
|
||||
)
|
||||
),
|
||||
)
|
||||
.all()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue