Skip to content
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

Closed
christophmayrhofer opened this issue Sep 13, 2023 · 3 comments

Comments

@christophmayrhofer
Copy link

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

@crynobone
Copy link
Member

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.

laravel new bug-report --github="--public"

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!

@christophmayrhofer
Copy link
Author

christophmayrhofer commented Sep 14, 2023

@crynobone
Copy link
Member

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.

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

No branches or pull requests

2 participants