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

Schema deterministic hashcode for DynamicValue #655

Open
carlos-verdes opened this issue Jan 30, 2024 · 5 comments
Open

Schema deterministic hashcode for DynamicValue #655

carlos-verdes opened this issue Jan 30, 2024 · 5 comments

Comments

@carlos-verdes
Copy link

I'm creating a ddd store for Entity and ValueObject.

ValueObject will use it's hashcode as key in the store (and I'll manage collisions storing a list instead of a single value object)

My current approach use something like this:

trait ValueObject[R]:

  def schema: Schema[R]

  extension (valueObject: R)
    def isSameValueObjectAs(other: R): Boolean =
      schema.diff(valueObject, other).isIdentical

    def valueHashCode: Long =
      schema.toDynamic(valueObject).hashCode

This way I can do something like store.getValueObject[T: ValueObject](valueObject: T).filter(found => found.isSameValueObjectAs(valueObject).runHead

However in my tests I observe the hashCode generated using DynamicValue changes, making my code fail.

@jdegoes
Copy link
Member

jdegoes commented Jun 8, 2024

/bounty $175

Copy link

algora-pbc bot commented Jun 8, 2024

💎 $175 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #655 with your implementation plan
  2. Submit work: Create a pull request including /claim #655 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-schema!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🟢 @BijenderKumar1 Jun 25, 2024, 3:53:55 AM #696

@BijenderKumar1
Copy link

BijenderKumar1 commented Jun 25, 2024

/attempt #655
I reproduced the issue by creating a DynamicValue object and logging the hashCode on repeated runs, and it does change. Diving deep into the issue, I observed that there is no implementation for the hashCode method in the DynamicValue class, and thus the original methods from the Any class are being used, leading to inconsistency. I am adding an implementation for the hashCode in the DynamicValue class to resolve the issue. Thanks!

Algora profile Completed bounties Tech Active attempts Options
@BijenderKumar1 1 ZIO bounty
Cancel attempt

Copy link

algora-pbc bot commented Jun 25, 2024

💡 @BijenderKumar1 submitted a pull request that claims the bounty. You can visit your bounty board to reward.

@BijenderKumar1
Copy link

@jdegoes Just a gentle reminder to please review my pull request. Thanks!

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

No branches or pull requests

3 participants