Remove the no longer used engine and connection globals
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m52s

Only `session` is used in the package.
Bound to the `engine`, it connects on its first query
instead of when the package is imported.
This commit is contained in:
Alexander Hess 2026-11-30 14:03:05 +01:00
commit 2b112f46e2
Signed by: alexander
GPG key ID: B46EDB4DFC26805D
3 changed files with 5 additions and 16 deletions

View file

@ -4,8 +4,6 @@ from velofy.db.addresses import Address
from velofy.db.addresses_addresses import Path from velofy.db.addresses_addresses import Path
from velofy.db.addresses_pixels import AddressPixelAssociation from velofy.db.addresses_pixels import AddressPixelAssociation
from velofy.db.cities import City from velofy.db.cities import City
from velofy.db.connection import connection
from velofy.db.connection import engine
from velofy.db.connection import session from velofy.db.connection import session
from velofy.db.couriers import Courier from velofy.db.couriers import Courier
from velofy.db.customers import Customer from velofy.db.customers import Customer

View file

@ -1,9 +1,9 @@
"""Provide connection utils for the ORM layer. """Provide connection utils for the ORM layer.
This module defines fully configured `engine`, `connection`, and `session` This module defines a fully configured `session` object
objects to be used as globals within the `velofy` package. to be used as a global within the `velofy` package.
If a database is not guaranteed to be available, they are set to `None`. If a database is not guaranteed to be available, it is set to `None`.
That is the case on the CI server. That is the case on the CI server.
""" """
@ -11,19 +11,15 @@ import os
from typing import cast from typing import cast
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy import engine as engine_mod
from sqlalchemy import orm from sqlalchemy import orm
import velofy import velofy
if os.getenv("TESTING"): if os.getenv("TESTING"):
# Placeholders that the test fixtures replace # Placeholder that the test fixtures replace
engine: engine_mod.Engine = None # type: ignore[assignment]
connection: engine_mod.Connection = None # type: ignore[assignment]
session: orm.Session = None # type: ignore[assignment] session: orm.Session = None # type: ignore[assignment]
else: # pragma: no cover else: # pragma: no cover
engine = sa.create_engine(cast(str, velofy.config.DATABASE_URI)) engine = sa.create_engine(cast(str, velofy.config.DATABASE_URI))
connection = engine.connect() session = orm.Session(bind=engine)
session = orm.sessionmaker(bind=connection)()

View file

@ -47,11 +47,6 @@ def db_connection(request):
engine = sa.create_engine(config.DATABASE_URI) engine = sa.create_engine(config.DATABASE_URI)
connection = engine.connect() connection = engine.connect()
# Monkey patch the package's global `engine` and `connection` objects,
# just in case if it is used somewhere in the code base.
db.engine = engine
db.connection = connection
if request.param == "all_at_once": if request.param == "all_at_once":
with connection.begin(): with connection.begin():
connection.execute(sa.text(f"CREATE SCHEMA {config.CLEAN_SCHEMA};")) connection.execute(sa.text(f"CREATE SCHEMA {config.CLEAN_SCHEMA};"))