-
Notifications
You must be signed in to change notification settings - Fork 176
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
case class default values are non-lazy #1218
Comments
P.S. It breaks even when it's nested inside a nullable field; import pureconfig._
import pureconfig.generic.auto._
case class Foo(bar: String, baz: Option[String] = ???)
case class Blah(hello: String, world: Option[Foo])
ConfigSource.string("{ hello: hey }").load[Blah] which again makes:
I would expect this to never even try instantiating a |
Hi @dontgitit, thanks for filing this issue. Indeed, it looks like we are instantiating defaults earlier than we need to and that might be a problem (though I wouldn't recommend setting any kind of heavy logic, particularly stateful logic, in the defaults of config classes). I'm not sure we can avoid computing all defaults in all cases, but I'll look into it. |
Absolutely! |
Hi @dontgitit, a very late update on this: at the time I investigated the possibility of making default values lazy, but unfortunately it seems to be out of our control. We rely on shapeless's I guess my only recommendation would be really to use only simple side-effect free fields as defaults. With a bit of extra boilerplate, one can always achieve the same functionality and keep impure logic separate, e.g.: case class MyConfig(myTag: Option[String]) {
def myTagValue: String = myTagValue.getOrElse(getFromAWS())
} |
That makes sense. Thanks for taking a look! |
This was fixed in #1636 for Scala 3. We have no plans to back port this to Scala 2 due to shapeless limitations, so I'm going to close this as completed. |
the above produces:
I would expect it to produce
Right(SampleConf(bar))
sincefoo
is defined. It seems the default values are being invoked even if they're unneeded. This example is a little egregious (using???
) but the default value might involve a complex operation that we don't want to be computed if it's unnecessary.The text was updated successfully, but these errors were encountered: