-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MissingAttributeException does not get thrown for properties with casts #48387
Comments
Hey there, thanks for reporting this issue. We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.
Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue. Thanks! |
Based on the original PR this seems to be expected as it only covers Attribute accessors and mutators.
A feature request would be the right path here, feel free to submit a PR if you can. |
Laravel Version
10.x
PHP Version
8.2
Database Driver & Version
mysql 8
Description
I realized that accessing missing attributes that have a cast does not throw a MissingAttributeException.
It seems that it is because there is an early return for attributes with casts that happens before the MissingAttribute check:
https://github.com/laravel/framework/blob/10.x/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php#L428
Is that expected behavior? Would it cause problems if we move the MissingAttribute to the beginning of the method?
Steps To Reproduce
create a model with two properties
add one of the two properties to the casts array
query the model and do not add those two columns to the select statement
enable strict mode
try to access the two properties
it will return null for the one with the cast and it will throw a MissingAttributeException for the one without a cast
The text was updated successfully, but these errors were encountered: