fix: host_cli __main__ and cross-module FK autogen (#86, #89) - #91
Merged
Conversation
- 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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes two well-defined framework papercuts surfaced in recent issues.
#89 —
python -m simple_module_hosting.host_clisilently no-opsframework/hosting/simple_module_hosting/__main__.pysopython -m simple_module_hosting [...]invokes the Typer app instead of importing-and-exiting.if __name__ == "__main__": app()block at the bottom ofhost_cli.pyso the exact form documented in the issue (python -m simple_module_hosting.host_cli) also works.sm-hostconsole script via[project.scripts]inframework/hosting/pyproject.toml, matching the typer app'sname="sm-host"and giving users a discoverableuv run sm-host gen-pages.#86 — alembic autogen emits spurious
drop_constraintfor cross-module FKsmake_include_object(metadata, *, ignore_unmodeled_fks: bool = True)inframework/db/simple_module_db/migrations.pynow 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.ignore_unmodeled_fks=Falseto opt back into the prior behaviour.Test plan
uv run pytest framework/db framework/hosting— 129 passeduv run ruff check+uv run ruff format --checkclean on touched filesuv run ty check framework/hosting/simple_module_hosting/ framework/db/simple_module_db/— all checks passedtest_module_entrypoint_runs_cli/test_host_cli_module_dunder_main_runs_cli— exercise bothpython -minvocation forms via subprocesstest_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 parentsOut 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