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

Fix/rails 7.1.2 compatibility #436

Closed

Conversation

adifsgaid
Copy link

@adifsgaid adifsgaid commented Nov 21, 2023

Description

After upgrading to Rails 7.1.2, our application encounters a NoMethodError when attempting to access config on a nil object within factory_bot_rails. This issue is reproduced when the application is booting and seems to be related to the factory_bot_rails Railtie initialization process.

Environment

  • Rails Version: 7.1.2
  • Ruby Version: 3.2.2
  • FactoryBotRails Version: 6.4.0

Error Output

/usr/local/bundle/gems/railties-7.1.2/lib/rails.rb:51:in configuration': undefined method config' for nil:NilClass (NoMethodError)

Steps to Reproduce

  1. Upgrade a Rails application to version 7.1.2.
  2. Use factory_bot_rails gem version 6.4.0.
  3. Boot the application.

Expected Behavior

The application should boot without errors, and factory_bot_rails should correctly integrate with the Rails application configuration.

Actual Behavior

The application fails to boot, raising a NoMethodError related to config.

Proposed Fix

The changes proposed in PR 8205851 seem to address the issue by ensuring that config is accessed in a way that is compatible with Rails 7.1.2's initialization process, I was not aware of the PR until now 😅 . It modifies the Railtie to defer the loading of factory_bot_rails until active_record is fully loaded, avoiding the NoMethodError.

I have applied the changes from the PR locally and confirmed that it resolves the error. This PR would be valuable for others who may face the same issue upon upgrading.

Additional Information

If there is any additional information or testing required, please let me know. I am willing to assist in any way to get this issue resolved.

@adifsgaid adifsgaid changed the base branch from master to main November 21, 2023 10:05
@jmeattle
Copy link

jmeattle commented Nov 21, 2023

Similar error in Rails 6.1.7.6 upon upgrading from factory_bot_rails 6.2.0 to 6.4.0:

ruby/gems/3.1.0/gems/railties-6.1.7.6/lib/rails.rb:47:in `configuration': undefined method `config' for nil:NilClass (NoMethodError)

@scott-knight
Copy link

Experiencing the same issue. Thanks for posting the PR!

@jurgens
Copy link

jurgens commented Nov 22, 2023

thumbs up, bumped into this error in two different projects

@bloolizard
Copy link

Having same issue

@bloolizard
Copy link

Tried this fix, although not getting error, tests are still failing. Might be related to 7.1.2, as I'm upgrading too.
Screenshot from 2023-11-22 14-24-11

@rnestler
Copy link

This looks like a duplicate of #432

@adifsgaid
Copy link
Author

adifsgaid commented Nov 23, 2023

@rnestler, Yes, as I mentioned here:

The changes proposed in PR 8205851 seem to address the issue by ensuring that config is accessed in a way that is compatible with Rails 7.1.2's initialization process, I was not aware of the PR until now 😅 . It modifies the Railtie to defer the loading of factory_bot_rails until active_record is fully loaded, avoiding the NoMethodError.

I was an aware at that time, I added the tests for the PR, hopefully it will get merged soon 😊 , and I will close this PR, either way thanks for the remark.

@neilvcarvalho
Copy link
Member

This PR's commits were cherry-picked to #440, and this fix was released: https://github.com/thoughtbot/factory_bot_rails/releases/tag/v6.4.2

Thank you for working on this!

@bloolizard
Copy link

Thanks for working on this, can verify it's working 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.

7 participants