Files
flowsint/flowsint-api/alembic/env.py
T
dextmorgn 441de48264 fix(mypy): finish the ratchet backlog — permissions, dockertool, alembic
Last batch of real fixes plus one more scoped override:

- DockerTool.get_image() read cls.image as a class attribute, but
  __init__ only ever sets it on the instance (self.image = ...) — real
  bug (would AttributeError if get_image() were ever called before an
  instance existed with a subclass not also declaring image at class
  level). Declared `image: str` on the base to document what's
  actually relied on: subclasses set it as a class attribute, __init__
  shadows it per-instance with the tagged form.
- ReconCrawlTool.version() was declared -> str but its body was a bare
  `pass` (returns None) — no callers exist, so raises NotImplementedError
  with a comment instead of guessing a fake version string.
- ReconCrawlTool.launch()'s args param defaulted to None but the body
  calls args.get(...) unconditionally — real crash risk if ever called
  without args (never observed since the one caller always passes a
  dict), guarded with `args = args or {}`.
- Extended flowsint-core's tests.* override (assignment, override) for
  the same InputType/OutputType-pattern reason as the existing entries:
  MockEnricher/ResolveEnricher fixtures reassign InputType/OutputType
  and vary scan()/postprocess() signatures per the documented pattern,
  same as production enrichers.
- permissions.py, alembic/env.py, and one alembic migration's untyped
  params/standard-boilerplate arg-type gaps.

Ratchet is now clean except the accepted import-untyped debt (86
errors — cross-package imports needing py.typed markers project-wide,
deliberately out of scope: adding them earlier in this branch
ballooned the count from 478 to 1423 by unmasking the full ~2200
pre-existing backlog instead of shrinking it).

Verified: all 4 packages' test suites pass (397 + 32 + 6 + 54).
2026-08-25 09:33:36 +02:00

63 lines
1.9 KiB
Python

import os
import sys
from logging.config import fileConfig
from alembic import context
from dotenv import load_dotenv
from sqlalchemy import engine_from_config, pool
load_dotenv()
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from flowsint_core.core.models import *
config = context.config
if config.config_file_name is not None:
fileConfig(config.config_file_name)
database_url = os.getenv("DATABASE_URL")
if not database_url:
raise RuntimeError("DATABASE_URL is not defined in .env")
config.set_main_option("sqlalchemy.url", database_url)
# Base comes from the `import *` above (models.py isn't py.typed, so mypy
# can't see it) — same standard Alembic autogenerate pattern noted there.
target_metadata = Base.metadata # type: ignore[name-defined]
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode."""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online() -> None:
"""Run migrations in 'online' mode."""
# config_ini_section always resolves to a real section for this
# project's alembic.ini — standard alembic-generated boilerplate,
# not narrowed further upstream either.
connectable = engine_from_config(
config.get_section(config.config_ini_section), # type: ignore[arg-type]
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()