Make mypy work again #8
3 changed files with 5 additions and 16 deletions
Remove the no longer used engine and connection globals
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 1m52s
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.
commit
2b112f46e2
|
|
@ -4,8 +4,6 @@ from velofy.db.addresses import Address
|
|||
from velofy.db.addresses_addresses import Path
|
||||
from velofy.db.addresses_pixels import AddressPixelAssociation
|
||||
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.couriers import Courier
|
||||
from velofy.db.customers import Customer
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
"""Provide connection utils for the ORM layer.
|
||||
|
||||
This module defines fully configured `engine`, `connection`, and `session`
|
||||
objects to be used as globals within the `velofy` package.
|
||||
This module defines a fully configured `session` object
|
||||
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.
|
||||
"""
|
||||
|
||||
|
|
@ -11,19 +11,15 @@ import os
|
|||
from typing import cast
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import engine as engine_mod
|
||||
from sqlalchemy import orm
|
||||
|
||||
import velofy
|
||||
|
||||
|
||||
if os.getenv("TESTING"):
|
||||
# Placeholders that the test fixtures replace
|
||||
engine: engine_mod.Engine = None # type: ignore[assignment]
|
||||
connection: engine_mod.Connection = None # type: ignore[assignment]
|
||||
# Placeholder that the test fixtures replace
|
||||
session: orm.Session = None # type: ignore[assignment]
|
||||
|
||||
else: # pragma: no cover
|
||||
engine = sa.create_engine(cast(str, velofy.config.DATABASE_URI))
|
||||
connection = engine.connect()
|
||||
session = orm.sessionmaker(bind=connection)()
|
||||
session = orm.Session(bind=engine)
|
||||
|
|
|
|||
|
|
@ -47,11 +47,6 @@ def db_connection(request):
|
|||
engine = sa.create_engine(config.DATABASE_URI)
|
||||
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":
|
||||
with connection.begin():
|
||||
connection.execute(sa.text(f"CREATE SCHEMA {config.CLEAN_SCHEMA};"))
|
||||
|
|
|
|||
Loading…
Reference in a new issue