-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Redefining class regression: undefined method `config' for class #88
Comments
I wouldn't say a regression per se, dry-configurable is not developed with this case in mind. I think your code worked "by accident", even in Rails environment classes are not meant to be loaded more than once. Yes, they are re-loaded but every time old constants are removed. That being said, it's surprising the Class.new.include(Dry::Configurable).include(Dry::Configurable)
NameError: undefined method `config' for class `#<Class:0x00007fa984607810>' |
I'm not sure what to do in such situations. Raise an error? Emit a warning and fallback gracefully? |
@solnic I am a little biased here, but I would prefer a solution that would behave similar to the 0.9 behavior. Perhaps a graceful fallback with an optional warning? @flash-gordon thanks for your feedback, I will take a deeper look at why we reload classes multiple times. |
@solnic @mitnal I think it should raise an error, nobody should develop an app intentionally allowing their code to be run twice. Even if it's fine for them it's defo not OK for literally everyone else :) We had the same issue in dry-struct actually, now it raises an exception. This was a "breaking change", sort of, but after a while, people stopped creating issues about repeated class definitions (dry-rb/dry-struct#35). |
Yeah I agree with @flash-gordon - if your code loads the same class more than once, then you may have issues. Covering it up on the library side doesn't seem to be a solution. I'm closing this in favor of #89 |
Describe the bug
We use
dry-configurable
in our Rails project. In 0.9 we had no problems but since the upgrade to 0.11 we get the following error:After a little bit of digging I found out that it is only a problem the second time we define the class (That the class is redefined twice at all could be a Rails autoloading thing).
To Reproduce
Expected behavior
(dry-configurable v0.9 behavior, also notice the different return value (nil instead of App))
Your environment
The text was updated successfully, but these errors were encountered: