doobie icon indicating copy to clipboard operation
doobie copied to clipboard

1.0.0-RC6: `import doobie.implicits._` is not source compatible.

Open notxcain opened this issue 1 year ago • 10 comments

It looks like the imported auto-derivation takes precedence over explicitly defined instances available in scope when Option is involved.

Reproducer:

Scastie

case class Person(
  id: Int,
  name: String,
  address: Option[Address]
)

case class Address(
  city: String,
  street: String,
  zip: Int
)

trait Codecs {
  import doobie._
  
  // Ignore the correctness
  implicit val addressGet: Get[Address] = 
    Get[String].map(_ => Address("", "", 1))
}

import doobie._
import doobie.implicits._

object Dao extends Codecs {
  val autoderived: Read[Person] = Read[Person]
}

assert(Dao.autoderived.length == 3)

// Dao.autoderived.length is 5

notxcain avatar Sep 19 '24 15:09 notxcain

Managed to write an even shorter reproducer. The issue is with the combination of a field wrapped in Option and auto-derivation.

notxcain avatar Sep 19 '24 15:09 notxcain

Thank you for the report & repro @notxcain! Someone else have the same issue too https://discord.com/channels/632277896739946517/632727524434247691/1286285929690169415

I think I know what needs to be done to fix this 🔨

jatcwang avatar Sep 19 '24 16:09 jatcwang

Awesome! Thanks for the enormous effort with the RC6 🤝🏼

notxcain avatar Sep 19 '24 16:09 notxcain

Hello @jatcwang , at our company, we're loving users of Doobie. We were considering to update to RC6, but it seems like it's better to wait for RC7. Do you think RC7 will be released sometime this or next week?

sideeffffect avatar Sep 24 '24 15:09 sideeffffect

Hey @sideeffffect I'm knee deep in implicit prioritization land right now trying to sort it out 😄 Yes I think waiting for RC7 is the better idea unless you're not dependent on any custom Meta/Read/Write instances.

I'm currently trying a variation of Circe's Exported to fix this. Can't promise a timeline though sorry - These things either work or don't. Will push some changes for ideas/review if I'm stuck.

jatcwang avatar Sep 24 '24 16:09 jatcwang

Thank you @jatcwang for all your hard work :heart: Hang in there and good luck! :four_leaf_clover:

sideeffffect avatar Sep 25 '24 09:09 sideeffffect

So..the good news is the general approach works. However, while testing I discovered that because doobie has always relied on auto-derivation. You can not simply take a Read/Write[A] instance and produce Read/Write[Option[A]]. The latter have to be completely derived from scratch. That's something we can change but involves changing the implementation of Write / Read.. :hammer:

jatcwang avatar Sep 28 '24 15:09 jatcwang

Would you consider marking 1.0.0-RC5 as the latest release as another way to discourage people from looking at 1.0.0-RC6?

https://github.com/typelevel/doobie/releases/edit/v1.0.0-RC5

image

jsoref avatar Oct 08 '24 15:10 jsoref

Good idea thanks. Done :)

jatcwang avatar Oct 08 '24 15:10 jatcwang

Just a quick update. The rework on Write/Read seems to have panned out and there's a clear path forward, I'm working on having it it all working across Scala 2 & 3 + better test coverage of the edge cases

jatcwang avatar Oct 20 '24 21:10 jatcwang

The necessary changes should be on main branch now. If you got a moment please give the snapshot version a go and let me know if anything is broken for you!

The version number should be 1.0-0f190f4-SNAPSHOT (You can use any recent git commit hash on main too)

You most likely need to include this resolver in build.sbt

resolvers ++= Resolver.sonatypeOssRepos("snapshots")

jatcwang avatar Jan 10 '25 22:01 jatcwang