Skip to content

Fix make command stubs, register db:make:observer, fix db:make:model flags - #294

Open
claude-tmgbedu wants to merge 7 commits into
mainfrom
task/observer-stub-cleanup
Open

claude-tmgbedu wants to merge 7 commits into
mainfrom
task/observer-stub-cleanup

Conversation

@claude-tmgbedu

@claude-tmgbedu claude-tmgbedu commented Oct 21, 2026 •

Copy link
Copy Markdown

Generated observers and models didn't import, the observer generator couldn't be run, and db:make:model --migration / --seeder failed.

observer.stub

  • It imported Model from masoniteorm.models, which the framework doesn't install, so importing a generated observer raised ModuleNotFoundError. It now imports from fastapi_startkit.masoniteorm.models.
  • It stubbed booted/booting/hydrating/hydrated, which never fire. It now has the eight events from Model lifecycle events, automatic timestamps and datetime casts #291, in dispatch order: saving, creating, updating, created, updated, saved, deleting, deleted. They are async def <event>(self, <model>: Model) -> None, and observe_events awaits them.
  • The docstrings are gone.

model.stub

  • It had the same stale import, so every model generated by db:make:model failed to import. The import is fixed and the docstrings are gone.

make:observer

  • MakeObserverCommand was exported but never registered. It is renamed db:make:observer, matching db:make:migration and db:make:model, and DatabaseProvider registers it. The old name observer was never reachable from artisan, so nothing depended on it.

db:make:model --migration / --seeder
Both failed on 0.67.0:

$ python artisan db:make:model Widget --migration
The command "migration" does not exist.
$ python artisan db:make:model Gadget --seeder
Not enough arguments (missing: "name")
  • --migration now calls db:make:migration.
  • Both nested calls go through call_command(name, arguments), which puts the command name first. Cleo's Command.call binds its args against the application definition, whose first positional is command, so without the prefix the first argument was taken as the command name and lost. The fix stays in MakeModelCommand instead of overriding call on the core console Command, because this is the only working caller.

ADR 028 and its index row are updated (renumbered from 026, which is taken by #292; #293 has 027).

Validation

  • New tests:
    • A generated model imports and subclasses Model.
    • A generated observer imports, its handlers are exactly the eight events in order, and each one dispatches through observe_events.
    • app.run("db:make:observer", "Order") works on an app booted with DatabaseProvider, the same path artisan uses. It fails when the registration is removed.
    • app.run("db:make:model", ...) with --migration, --migration --table and --seeder creates the create/update migration and the seeder. All three fail without the fix.
  • Full suite, without the live-Postgres tests: 3037 passed, 10 skipped.
  • In a project created with uvx fastapi-startkit init, against this branch's build:
    • python artisan db:make:model Invoice and python artisan db:make:observer Invoice created files that both import.
    • python artisan db:make:model Receipt --migration --seeder created the model, migration and seeder, and python artisan db:migrate applied the migration.

Not in this PR

  • db:migrate:fresh --seed and db:migrate:refresh --seed call seed:run, which doesn't exist (it's db:seed). The call has the same argument problem, and it runs inside asyncio.run, so db:seed would start a second event loop. db:migrate:refresh also isn't registered. The fix needs the seeding restructured and new fixtures, which would push this PR past 10 files.

🤖 Generated with Claude Code

The generated observer imported Model from the uninstalled masoniteorm
package, stubbed events that never fire and carried docstrings. It now
imports from fastapi_startkit.masoniteorm.models and defines async handlers
for the eight dispatched events in order. A test imports the generated file
and dispatches every event.
The model stub imported Model from the uninstalled masoniteorm package, so
every generated model failed to import. The observer command was never
registered, so artisan could not run it; it is now db:make:observer,
matching the other db:make commands, and DatabaseProvider registers it.
@claude-tmgbedu claude-tmgbedu changed the title Match observer stub to model lifecycle events Fix observer and model stubs; register db:make:observer Oct 21, 2026
ADR 026 and 027 are taken by open PRs #292 and #293.
@codecov

codecov Bot commented Oct 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

--migration called the unregistered "migration" command. Both flags also
failed because Cleo's call binds its arguments against the application
definition, which takes the first word as the command name. Nested calls
now pass the command name first.
@claude-tmgbedu claude-tmgbedu changed the title Fix observer and model stubs; register db:make:observer Fix make command stubs, register db:make:observer, fix db:make:model flags Oct 21, 2026
tmgbedu and others added 3 commits October 21, 2026 13:04
…eanup

# Conflicts:
#	fastapi_startkit/tests/masoniteorm/commands/test_make_commands.py
This is a bug fix, not a design decision; remove ADR 028 and its
docs/adr/AGENTS.md index row while keeping the fixes and tests.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

3 participants