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

Protobuf conversion bug #1001

Open
gafiatulin opened this issue Jul 15, 2024 · 0 comments
Open

Protobuf conversion bug #1001

gafiatulin opened this issue Jul 15, 2024 · 0 comments

Comments

@gafiatulin
Copy link

gafiatulin commented Jul 15, 2024

It appears that at some point during conversion to protobuf entity-builder instance cache is used, but it looks like builders are mutable and are not reset to initial clean state which leads to incorrect results.

Reproduction (click to expand):

Given
definition.proto:

syntax = "proto3";

message DataEntryPb {
  string key = 1;
  string value = 2;
}

message EntityPb {
  string entityId = 1;
  repeated DataEntryPb metadata = 2;
}

message MultiEntityPb {
  string multiEntityId = 1;
  repeated EntityPb entities = 2;
}

and
Reproduction.scala:

import magnolify.protobuf._

object Reproduction extends App{

  final case class DataEntry(key: String, value: String)
  final case class Entity(entityId: String, metadata: Seq[DataEntry])
  final case class MultiEntity(multiEntityId: String, entities: Seq[Entity])

  val me = MultiEntity(
    "me1",
    Seq(
      Entity("entity1", Seq(DataEntry("key1", "value1"))),
      Entity("entity2", Seq.empty),
    ),
  )

  val pbType = ProtobufType[MultiEntity, Definition.MultiEntityPb]


  val x = pbType.to(me)

  println(x)
}

Produces the following:

multiEntityId: "me1"
entities {
  entityId: "entity1"
  metadata {
    key: "key1"
    value: "value1"
  }
}
entities {
  entityId: "entity2"
  metadata {
    key: "key1"
    value: "value1"
  }
}

Note that metadata is supposed to be empty for the second entity.

@gafiatulin gafiatulin changed the title Protobuf conversion problem Protobuf conversion bug Jul 15, 2024
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