fix(orm): use type().__name__ in find_or_fail and first_or_fail exception messages#91
Merged
Merged
Conversation
…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>
48cd353 to
d4abaf0
Compare
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
self._modelinQueryBuilderis always a model instance (set vianew_query()→set_model(self)), not a classinstance.__name__silently routes through__getattr__→get_attribute("__name__")→None(no such DB column)find_or_failandfirst_or_failto usetype(self._model).__name__, which correctly resolves to the model class name (e.g."User")Test plan
tests/masoniteorm/sqlite/builder/test_sqlite_builder_find_or_fail.pyaddedfind_or_fail(1)returns the seeded recordfind_or_fail(999999)raisesModelNotFoundException"User", not"type"or"None"first_or_fail🤖 Generated with Claude Code