Use the sa alias for sqlalchemy everywhere

`sa` is the common alias, also in SQLAlchemy's own documentation
This commit is contained in:
Alexander Hess 2026-11-30 14:17:49 +01:00
commit e30b3efbe8
Signed by: alexander
GPG key ID: B46EDB4DFC26805D
9 changed files with 29 additions and 29 deletions

View file

@ -3,7 +3,7 @@
import datetime as dt import datetime as dt
import pytest import pytest
import sqlalchemy as sqla import sqlalchemy as sa
from sqlalchemy import exc as sa_exc from sqlalchemy import exc as sa_exc
from tests import config as test_config from tests import config as test_config
@ -44,7 +44,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.ReplaySimulation).where( stmt = sa.delete(db.ReplaySimulation).where(
db.ReplaySimulation.id == replayed_order.simulation.id, db.ReplaySimulation.id == replayed_order.simulation.id,
) )
@ -60,7 +60,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.Order).where(db.Order.id == replayed_order.actual.id) stmt = sa.delete(db.Order).where(db.Order.id == replayed_order.actual.id)
with pytest.raises(sa_exc.IntegrityError, match="fk_replayed_orders_to_orders"): with pytest.raises(sa_exc.IntegrityError, match="fk_replayed_orders_to_orders"):
db_session.execute(stmt) db_session.execute(stmt)
@ -80,7 +80,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.Courier).where(db.Courier.id == replayed_order.courier.id) stmt = sa.delete(db.Courier).where(db.Courier.id == replayed_order.courier.id)
with pytest.raises( with pytest.raises(
sa_exc.IntegrityError, sa_exc.IntegrityError,

View file

@ -1,7 +1,7 @@
"""Test the ORM's `Address` model.""" """Test the ORM's `Address` model."""
import pytest import pytest
import sqlalchemy as sqla import sqlalchemy as sa
from sqlalchemy import exc as sa_exc from sqlalchemy import exc as sa_exc
from velofy import db from velofy import db
@ -57,7 +57,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.City).where(db.City.id == address.city.id) stmt = sa.delete(db.City).where(db.City.id == address.city.id)
with pytest.raises( with pytest.raises(
sa_exc.IntegrityError, sa_exc.IntegrityError,

View file

@ -4,7 +4,7 @@ import json
import googlemaps import googlemaps
import pytest import pytest
import sqlalchemy as sqla import sqlalchemy as sa
from geopy import distance from geopy import distance
from sqlalchemy import exc as sa_exc from sqlalchemy import exc as sa_exc
@ -73,7 +73,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.Address).where(db.Address.id == path.first_address.id) stmt = sa.delete(db.Address).where(db.Address.id == path.first_address.id)
with pytest.raises( with pytest.raises(
sa_exc.IntegrityError, sa_exc.IntegrityError,
@ -87,7 +87,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.Address).where(db.Address.id == path.second_address.id) stmt = sa.delete(db.Address).where(db.Address.id == path.second_address.id)
with pytest.raises( with pytest.raises(
sa_exc.IntegrityError, sa_exc.IntegrityError,
@ -103,7 +103,7 @@ class TestConstraints:
# Must insert without ORM as otherwise SQLAlchemy figures out # Must insert without ORM as otherwise SQLAlchemy figures out
# that something is wrong before any query is sent to the database. # that something is wrong before any query is sent to the database.
stmt = sqla.insert(db.Path).values( stmt = sa.insert(db.Path).values(
first_address_id=address.id, first_address_id=address.id,
second_address_id=another_address.id, second_address_id=another_address.id,
city_id=999, city_id=999,
@ -123,7 +123,7 @@ class TestConstraints:
# Must insert without ORM as otherwise SQLAlchemy figures out # Must insert without ORM as otherwise SQLAlchemy figures out
# that something is wrong before any query is sent to the database. # that something is wrong before any query is sent to the database.
stmt = sqla.insert(db.Path).values( stmt = sa.insert(db.Path).values(
first_address_id=path.first_address.id, first_address_id=path.first_address.id,
second_address_id=path.second_address.id, second_address_id=path.second_address.id,
city_id=path.city_id, city_id=path.city_id,

View file

@ -10,7 +10,7 @@ Implementation notes:
""" """
import pytest import pytest
import sqlalchemy as sqla import sqlalchemy as sa
from sqlalchemy import exc as sa_exc from sqlalchemy import exc as sa_exc
from velofy import db from velofy import db
@ -56,7 +56,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.Address).where(db.Address.id == assoc.address.id) stmt = sa.delete(db.Address).where(db.Address.id == assoc.address.id)
with pytest.raises( with pytest.raises(
sa_exc.IntegrityError, sa_exc.IntegrityError,
@ -72,7 +72,7 @@ class TestConstraints:
# Must insert without ORM as otherwise SQLAlchemy figures out # Must insert without ORM as otherwise SQLAlchemy figures out
# that something is wrong before any query is sent to the database. # that something is wrong before any query is sent to the database.
stmt = sqla.insert(db.AddressPixelAssociation).values( stmt = sa.insert(db.AddressPixelAssociation).values(
address_id=address.id, address_id=address.id,
city_id=999, city_id=999,
grid_id=pixel.grid.id, grid_id=pixel.grid.id,
@ -93,7 +93,7 @@ class TestConstraints:
# Must insert without ORM as otherwise SQLAlchemy figures out # Must insert without ORM as otherwise SQLAlchemy figures out
# that something is wrong before any query is sent to the database. # that something is wrong before any query is sent to the database.
stmt = sqla.insert(db.AddressPixelAssociation).values( stmt = sa.insert(db.AddressPixelAssociation).values(
address_id=address.id, address_id=address.id,
city_id=address.city.id, city_id=address.city.id,
grid_id=999, grid_id=999,
@ -112,7 +112,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.Pixel).where(db.Pixel.id == assoc.pixel.id) stmt = sa.delete(db.Pixel).where(db.Pixel.id == assoc.pixel.id)
with pytest.raises( with pytest.raises(
sa_exc.IntegrityError, sa_exc.IntegrityError,

View file

@ -4,7 +4,7 @@ import datetime as dt
import pandas as pd import pandas as pd
import pytest import pytest
import sqlalchemy as sqla import sqlalchemy as sa
from sqlalchemy import exc as sa_exc from sqlalchemy import exc as sa_exc
from tests import config as test_config from tests import config as test_config
@ -76,7 +76,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.Pixel).where(db.Pixel.id == forecast.pixel.id) stmt = sa.delete(db.Pixel).where(db.Pixel.id == forecast.pixel.id)
with pytest.raises( with pytest.raises(
sa_exc.IntegrityError, sa_exc.IntegrityError,

View file

@ -1,7 +1,7 @@
"""Test the ORM's `Grid` model.""" """Test the ORM's `Grid` model."""
import pytest import pytest
import sqlalchemy as sqla import sqlalchemy as sa
from sqlalchemy import exc as sa_exc from sqlalchemy import exc as sa_exc
from velofy import db from velofy import db
@ -41,7 +41,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.City).where(db.City.id == grid.city.id) stmt = sa.delete(db.City).where(db.City.id == grid.city.id)
with pytest.raises( with pytest.raises(
sa_exc.IntegrityError, sa_exc.IntegrityError,

View file

@ -4,7 +4,7 @@ import datetime as dt
import random import random
import pytest import pytest
import sqlalchemy as sqla import sqlalchemy as sa
from sqlalchemy import exc as sa_exc from sqlalchemy import exc as sa_exc
from tests import config as test_config from tests import config as test_config
@ -58,7 +58,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.Customer).where(db.Customer.id == order.customer.id) stmt = sa.delete(db.Customer).where(db.Customer.id == order.customer.id)
with pytest.raises(sa_exc.IntegrityError, match="fk_orders_to_customers"): with pytest.raises(sa_exc.IntegrityError, match="fk_orders_to_customers"):
db_session.execute(stmt) db_session.execute(stmt)
@ -69,7 +69,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.Courier).where(db.Courier.id == order.courier.id) stmt = sa.delete(db.Courier).where(db.Courier.id == order.courier.id)
with pytest.raises(sa_exc.IntegrityError, match="fk_orders_to_couriers"): with pytest.raises(sa_exc.IntegrityError, match="fk_orders_to_couriers"):
db_session.execute(stmt) db_session.execute(stmt)
@ -80,7 +80,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.Restaurant).where(db.Restaurant.id == order.restaurant.id) stmt = sa.delete(db.Restaurant).where(db.Restaurant.id == order.restaurant.id)
with pytest.raises(sa_exc.IntegrityError, match="fk_orders_to_restaurants"): with pytest.raises(sa_exc.IntegrityError, match="fk_orders_to_restaurants"):
db_session.execute(stmt) db_session.execute(stmt)
@ -112,7 +112,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.Address).where(db.Address.id == order.delivery_address.id) stmt = sa.delete(db.Address).where(db.Address.id == order.delivery_address.id)
with pytest.raises(sa_exc.IntegrityError, match="fk_orders_to_addresses"): with pytest.raises(sa_exc.IntegrityError, match="fk_orders_to_addresses"):
db_session.execute(stmt) db_session.execute(stmt)

View file

@ -1,7 +1,7 @@
"""Test the ORM's `Pixel` model.""" """Test the ORM's `Pixel` model."""
import pytest import pytest
import sqlalchemy as sqla import sqlalchemy as sa
from sqlalchemy import exc as sa_exc from sqlalchemy import exc as sa_exc
from velofy import db from velofy import db
@ -41,7 +41,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.Grid).where(db.Grid.id == pixel.grid.id) stmt = sa.delete(db.Grid).where(db.Grid.id == pixel.grid.id)
with pytest.raises( with pytest.raises(
sa_exc.IntegrityError, sa_exc.IntegrityError,

View file

@ -1,7 +1,7 @@
"""Test the ORM's `Restaurant` model.""" """Test the ORM's `Restaurant` model."""
import pytest import pytest
import sqlalchemy as sqla import sqlalchemy as sa
from sqlalchemy import exc as sa_exc from sqlalchemy import exc as sa_exc
from velofy import db from velofy import db
@ -41,7 +41,7 @@ class TestConstraints:
db_session.commit() db_session.commit()
# Must delete without ORM as otherwise an UPDATE statement is emitted. # Must delete without ORM as otherwise an UPDATE statement is emitted.
stmt = sqla.delete(db.Address).where(db.Address.id == restaurant.address.id) stmt = sa.delete(db.Address).where(db.Address.id == restaurant.address.id)
with pytest.raises( with pytest.raises(
sa_exc.IntegrityError, sa_exc.IntegrityError,