Skip to content

Include all user table columns in the UserFactory #1168

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

Merged

Conversation

markjaquith
Copy link
Contributor

Background

Jetstream creates migrations to add new columns in the user table, even if Jetstream isn't configured to use teams or profile pictures or 2FA. But because these fields are missing from the UserFactory that Jetstream installs, the default Jetstream tests will fail when using the Model::preventAccessingMissingAttributes() feature of model strictness.

These test failures are extremely unexpected when you've followed the happy path of Laravel, Jetstream, and then merely enabled model strictness. And the failures are not obvious. People who are new to Laravel seem likely to be very confused by these errors and might be dissuaded from using model strictness (and I do think people should be encouraged to use model strictness).

The Fix

Adding these missing fields to the factory prevents these exceptions, and allows the tests to pass.

Alternatives Considered

An alternative approach could be doing feature detection to alter the return of the UserFactory definition, and also doing feature detection in the templates, such that user data items for unused features aren't accessed. That seems a lot more complicated, when we could just add the default-null columns to the factory and be done.

fixes #1164

markjaquith and others added 2 commits October 21, 2022 13:57
Without these fields in the factory, the default Jetstream tests will
fail when using the Model::preventAccessingMissingAttributes() feature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@taylorotwell taylorotwell merged commit 611b5f5 into laravel:2.x Oct 21, 2022
@flick36
Copy link

flick36 commented Oct 21, 2022

might as well include 'current_team_id' => null then

@driesvints
Copy link
Member

@markjaquith this PR caused our build to fail

taylorotwell added a commit that referenced this pull request Oct 25, 2022
taylorotwell added a commit that referenced this pull request Oct 25, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…1170)

This reverts commit 611b5f5.
@taylorotwell
Copy link
Member

Reverted for now.

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.

Doesn't work with Laravel 9.35 Model::preventsAccessingMissingAttributes()
4 participants