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

Default implicit Success values can lead to unintentional retries #27

Open
ncreep opened this issue May 16, 2018 · 0 comments
Open

Default implicit Success values can lead to unintentional retries #27

ncreep opened this issue May 16, 2018 · 0 comments

Comments

@ncreep
Copy link

ncreep commented May 16, 2018

Hi,
Currently the Success object provides default Success implicits for various standard types:

implicit def either[A,B]: Success[Either[A,B]] =
  Success(_.isRight)
implicit def option[A]: Success[Option[A]] =
  Success(!_.isEmpty)
implicit def tried[A]: Success[Try[A]] =
  Success(_.isSuccess)

These are available even without explicit import. I found that this can lead to unintentional retries when forgetting to add your own implicit Success value.

For example, when querying a database I have a result type of Future[Option[???]], where an empty Option stands for a missing value in the database. In some use cases, this is a legitimate return value, and retrying the query won't change anything.

The correct behavior here would be to explicitly have:

implicit val always = Success.always

in scope.

But if you forget to add this line, everything still compiles and the option implicit from the Success object is picked up, leading to unwanted retries.

I would suggest removing the implicit modifier from defs above to avoid the unintentional retries.

Thanks

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

1 participant