Skip to content

Protobuf conversion bug #1001

@gafiatulin

Description

@gafiatulin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions