Skip to content

fix: host_cli __main__ and cross-module FK autogen (#86, #89) - #91

Merged
antosubash merged 2 commits into
mainfrom
claude/fix-github-issues-6EgTz
Apr 30, 2026
Merged

fix: host_cli __main__ and cross-module FK autogen (#86, #89)#91
antosubash merged 2 commits into
mainfrom
claude/fix-github-issues-6EgTz

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Summary

Closes two well-defined framework papercuts surfaced in recent issues.

#89python -m simple_module_hosting.host_cli silently no-ops

  • Added framework/hosting/simple_module_hosting/__main__.py so python -m simple_module_hosting [...] invokes the Typer app instead of importing-and-exiting.
  • Added an explicit if __name__ == "__main__": app() block at the bottom of host_cli.py so the exact form documented in the issue (python -m simple_module_hosting.host_cli) also works.
  • Installed a sm-host console script via [project.scripts] in framework/hosting/pyproject.toml, matching the typer app's name="sm-host" and giving users a discoverable uv run sm-host gen-pages.

#86 — alembic autogen emits spurious drop_constraint for cross-module FKs

  • make_include_object(metadata, *, ignore_unmodeled_fks: bool = True) in framework/db/simple_module_db/migrations.py now skips foreign-key constraints that exist in the live DB but not in target SQLModel metadata (compare_to is None). That's the framework's recommended cross-module FK pattern — declared at the migration level only — so those constraints look "unmodeled" to Alembic on every autogen run.
  • Default behaviour changes from "drop on sight" to "leave alone." Pass ignore_unmodeled_fks=False to opt back into the prior behaviour.
  • The table-level allowlist still applies, so FKs hung off unknown tables continue to be filtered out.

Test plan

  • uv run pytest framework/db framework/hosting — 129 passed
  • uv run ruff check + uv run ruff format --check clean on touched files
  • uv run ty check framework/hosting/simple_module_hosting/ framework/db/simple_module_db/ — all checks passed
  • New tests:
    • test_module_entrypoint_runs_cli / test_host_cli_module_dunder_main_runs_cli — exercise both python -m invocation forms via subprocess
    • test_include_object_skips_unmodeled_cross_module_fks_by_default — verifies the new default plus the opt-out flag plus that table-allowlist still rejects FKs on unknown parents

Out of scope

This PR intentionally addresses only the two most surgical issues. The other 9 open issues (#66, #68, #71, #73, #74, #75, #76, #81, #90) require larger design choices (worker bootstrap, env-var hierarchy, vite plugin shape, register_event_handlers signature change, etc.) and should land in their own PRs.

https://claude.ai/code/session_01Aqp73oTzfCxsLkfx2nBcbP


Generated by Claude Code

- Add `simple_module_hosting/__main__.py` and an explicit
  `if __name__ == "__main__": app()` block so
  `python -m simple_module_hosting[.host_cli]` actually invokes the
  Typer app instead of silently no-op'ing — which was breaking the
  documented `gen-pages` workflow without any error output.
- Install a `sm-host` console script via `[project.scripts]` so
  `uv run sm-host gen-pages` works as the typer help text implies.
- Teach `make_include_object` to skip foreign-key constraints that
  exist in the live DB but not in target SQLModel metadata (the
  recommended cross-module FK pattern). Defaults to ignoring those
  unmodeled FKs so autogenerate stops emitting spurious
  `op.drop_constraint(...)` calls every run; opt-out with
  `ignore_unmodeled_fks=False` to recover prior behaviour.

https://claude.ai/code/session_01Aqp73oTzfCxsLkfx2nBcbP
@antosubash
antosubash marked this pull request as ready for review April 30, 2026 19:44
- Parametrise the two near-identical `python -m ...` subprocess tests
  into a single test function rather than maintaining a duplicated body
  per invocation form.
- Trim per-line comments in the new cross-module-FK test that just
  restated what the code already shows; keep the docstring's WHY.

https://claude.ai/code/session_01Aqp73oTzfCxsLkfx2nBcbP
@antosubash
antosubash merged commit 6bc4dff into main Apr 30, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants