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

Investigation in Scala2/Scala3 decoder inconsistency #437

Merged
merged 6 commits into from
Jan 14, 2023

Conversation

GerretS
Copy link

@GerretS GerretS commented Jan 11, 2023

@alycklama and I noticed in #436 that certain built-in decoders have inconsistent behaviour between Scala 2 and 3.

Since this inconsistency is unrelated to our PR, we decided to make a separate issue to investigate this.

I think it is related to the Shapeless types used in the MapShapedCsvRowDecoder, since Shapeless makes heavy use of Macros which have changed in Scala 3. However, that is where my knowledge of Shapeless ends.

This PR adds a few unit tests that demonstrate the problem. They succeed on Scala 2 and fail on Scala 3.

@GerretS GerretS requested a review from a team as a code owner January 11, 2023 16:36
@alycklama
Copy link

I created a very simple case class OneColumn(name: String) to see if I can figure out what's going on. A bit of debugging into the code made me end-up at this point:

IndexedStateT:

  def run(initial: SA)(implicit F: FlatMap[F]): F[(SB, A)] =
    F.flatMap(runF)(f => f(initial))

initial is (name,None), which means that the column wasn't found. So far all is well.

However, when applying f on initial, the result is Right((List(),OneColumn())).

I would have expected a Left here, as the header is None. As I'm not familiar in how to debug this further, I hope this info is going to be useful!

@ybasket
Copy link
Collaborator

ybasket commented Jan 14, 2023

@GerretS @alycklama Thank you both for the investigation and debugging, your work has indeed proven useful for fixing!

I just pushed some commits that

  • fix the problem of not failing for missing columns
  • rewrite the corresponding test case to avoid unsafe effect running

It still fails for the test case with default value, but at least with correct error message. The underlying problem is more complex, the Scala 3 compiler for long did not allow to get default parameter values and AFAIK still has terrible UX nowadays as in you need -Yretain-tree, see softwaremill/magnolia#284. shapeless3 doesn't have support for it (yet), so probably the right™️ way would be to contribute it there and then use it here in fs2-data. If you scroll up in CsvRowDecoderTest, you'll see two test cases being commented out that would cover defaults. Do you need defaults in your usage of fs2-data or was it just something you discovered?

As the functionality of the test cases I didn't rewrite is more concisely covered by the existing test cases, I would remove those and then merge this PR – if that's fine for you?

@GerretS
Copy link
Author

GerretS commented Jan 14, 2023

Thanks for the fixes!

No, I don't think we'll need support for defaults, so we can go forward for now. I only noticed that situation by accident. It was the different handling of missing values that was causing trouble for us.

Feel free to clean up my test cases if they're already covered elsewhere, I didn't put too much thought into them other than to quickly demonstrate the issue.

Copy link
Member

@satabin satabin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the bug hunt and the fix!

@satabin satabin changed the base branch from main to 1.6.x January 14, 2023 15:01
Copy link
Member

@satabin satabin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not merge right now, doing some work to rebase it.

@satabin satabin added bug Something isn't working csv labels Jan 14, 2023
@satabin satabin added this to the 1.6.1 milestone Jan 14, 2023
@satabin satabin force-pushed the scala2-scala3-decoder-difference branch from ebcef92 to a3cafaa Compare January 14, 2023 15:06
Copy link
Member

@satabin satabin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok this can now be merged. Thanks again.

@satabin satabin force-pushed the scala2-scala3-decoder-difference branch from a3cafaa to dc0119d Compare January 14, 2023 15:24
@satabin satabin merged commit 119d782 into gnieh:1.6.x Jan 14, 2023
@GerretS GerretS deleted the scala2-scala3-decoder-difference branch January 14, 2023 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working csv
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants