Skip to content

fix(orm): use type().__name__ in find_or_fail and first_or_fail exception messages#91

Merged
bedus-creation merged 1 commit into
mainfrom
fix/find-or-fail-exception-message
Jun 6, 2026
Merged

fix(orm): use type().__name__ in find_or_fail and first_or_fail exception messages#91
bedus-creation merged 1 commit into
mainfrom
fix/find-or-fail-exception-message

Conversation

@bedus-creation

Copy link
Copy Markdown
Contributor

Summary

  • self._model in QueryBuilder is always a model instance (set via new_query()set_model(self)), not a class
  • instance.__name__ silently routes through __getattr__get_attribute("__name__")None (no such DB column)
  • Fixed both find_or_fail and first_or_fail to use type(self._model).__name__, which correctly resolves to the model class name (e.g. "User")

Test plan

  • New test file tests/masoniteorm/sqlite/builder/test_sqlite_builder_find_or_fail.py added
  • Happy path: find_or_fail(1) returns the seeded record
  • find_or_fail(999999) raises ModelNotFoundException
  • Exception message contains "User", not "type" or "None"
  • Same message assertion for first_or_fail
  • Full SQLite suite: 185 passed, 6 skipped, 0 failures

🤖 Generated with Claude Code

…tion messages

self._model is a model instance (not a class), so instance.__name__ routes
through __getattr__ → get_attribute("__name__") → None. Using type(self._model).__name__
correctly resolves to the class name (e.g. "User") in both find_or_fail and first_or_fail.

Adds a dedicated SQLite test suite covering the happy path, exception raising,
and asserting the model name appears in the message (not "type" or "None").

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bedus-creation bedus-creation force-pushed the fix/find-or-fail-exception-message branch from 48cd353 to d4abaf0 Compare June 6, 2026 03:53
@bedus-creation bedus-creation merged commit 3742d86 into main Jun 6, 2026
3 checks passed
@bedus-creation bedus-creation deleted the fix/find-or-fail-exception-message branch June 8, 2026 07:34
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.

1 participant