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

SchemaFor/Encoder/Decoder implicits not resolved when using case classes with a default value #553

Closed
improved-broccoli opened this issue Sep 16, 2020 · 11 comments
Labels

Comments

@improved-broccoli
Copy link

improved-broccoli commented Sep 16, 2020

When a case class have a field with a default value and a this constructor which sets field default value, this is how avrohugger generates case class implementing SpecificRecord API, compilation fail and output this:

could not find implicit value for evidence parameter of type com.sksamuel.avro4s.SchemaFor

Here is a snippet which reproduce the bug: https://scastie.scala-lang.org/mdQzDpRCQka2FnH80tDOSg

The bug happen under Scala 2.13.3 with latest version of avro4s and avrohugger.
But it appears to be a regression since it works until avro4s 3.0.9 and get broken from 3.1.0.

Thanks.

@improved-broccoli improved-broccoli changed the title Compilation issue when using a case class generated by avrohugger in GenericSerde SchemaFor/Encoder/Decoder not resolved when using case classes with a default value Sep 16, 2020
@improved-broccoli improved-broccoli changed the title SchemaFor/Encoder/Decoder not resolved when using case classes with a default value SchemaFor/Encoder/Decoder implicits not resolved when using case classes with a default value Sep 16, 2020
@andreas-schroeder
Copy link
Collaborator

Interesting; without having looked into it, I would expect issue to be in Magnolia's typeclass derivation logic. Have you tried to have some typeclass derived by pure Magnolia for your class?

@improved-broccoli
Copy link
Author

I had the same feeling it could be caused by Magnolia, but I don't understand very well Magnolia, so I were not able to do tests with it. You prefer I open a ticket on Magnolia?

@andreas-schroeder
Copy link
Collaborator

I was just wondering whether you already experimented with reproducing it with Magnolia. One other thing that I find actually intriguing is how the Scala compiler navigates the constructors in the non-working example, as there are now two zero-arg constructors. I guess the explicit constructor wins over the constructor with default argument...

@improved-broccoli
Copy link
Author

improved-broccoli commented Sep 24, 2020

I just wrote a new snippet to test Magnolia only and it appears the bug does not happen with 0.17.0 version, Avro4s is using 0.16.0 right now.
Could you consider to upgrade Magnolia version? If yes, I might try to submit a PR.
Here is the snippet with Magnolia 0.17.0: https://scastie.scala-lang.org/HyJeHOvNQlmy7eaBTtOGKQ

@stale
Copy link

stale bot commented Nov 23, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Nov 23, 2020
@improved-broccoli
Copy link
Author

@andreas-schroeder Any plan to update Magnolia to 0.17 in a near future?
Thanks.

@stale stale bot removed the wontfix label Nov 25, 2020
@propensive
Copy link

I've heard from @SethTisue that Avro4s is using the older version of Magnolia due to a bug, though I can't find any more details on that. But there's a further motivation for upgrading which is that it's blocking a few things in the Scala Community Build.

Notwithstanding this issue, I may be able to offer some help here, if we need a new version of Magnoila published to maintain support for Avro4s.

@SethTisue
Copy link
Contributor

SethTisue commented Nov 27, 2020

Avro4s is using the older version of Magnolia due to a bug, though I can't find any more details on that

I don't remember what happened exactly, but perhaps there isn't any "bug", it might simply be that upgrading to newer Magnolia required making some source adjustments that I chose not to tackle

@sksamuel
Copy link
Owner

I've upgraded avro4s to use magnolia 0.17 and released this as avro4s 4.0.3.

@stale
Copy link

stale bot commented Jan 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 26, 2021
@improved-broccoli
Copy link
Author

Now works on 4.0.3+ https://scastie.scala-lang.org/UIQVRzPQQfGLlV7YA2kz3g
Thanks @sksamuel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants