nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: hamba/avro
Pull request #452 (2024-09-15 19:00:33)

Fix: decode in the case of field missing in both writer binary and reader struct.
I think I overlooked an edge case the last time I worked on schema evolution:

If a field is missing in both the binary and the reader struct, it should be ignored rather than calling skipDecoder (which technically performs a read and moves the cursor).

The current implementation might perform a dirty read, causing errors like:

> unexpected EOF

> ReadString: size is greater than `Config.MaxByteSliceSize`


Patch:
diff --git a/codec_record.go b/codec_record.go
index 4a01b12..d07a4aa 100644
--- a/codec_record.go
+++ b/codec_record.go
@@ -76,9 +76,17 @@ func decoderOfStruct(d *decoderContext, schema Schema, typ reflect2.Type) ValDec
 				}
 			}
 		}
-
-		// Skip field if it doesnt exist
+		// Skip field if it doesn't exist
 		if sf == nil {
+			// If the field value doesn't exist in the binary, ignore it instead of
+			// appending a 'SkipDecoder'.
+			//
+			// Note: 'SkipDecoder' performs a read and moves the cursor, which,
+			// in this case, will lead to a dirty read.
+			if field.action == FieldSetDefault {
+				continue
+			}
+
 			fields = append(fields, &structFieldDecoder{
 				decoder: createSkipDecoder(field.Type()),
 			})


Test patch:
diff --git a/schema_compatibility_test.go b/schema_compatibility_test.go
index 83485cd..0b48254 100644
--- a/schema_compatibility_test.go
+++ b/schema_compatibility_test.go
@@ -976,3 +976,44 @@ func TestSchemaCompatibility_ResolveWithComplexUnion(t *testing.T) {
 	want := map[string]any{"b": []byte("foo")}
 	assert.Equal(t, want, result)
 }
+
+func TestSchemaCompatibility_ResolveWithFieldMissingInWriterAndReaderStruct(t *testing.T) {
+	w := avro.MustParse(`{
+				"type":"record", "name":"test", "namespace": "org.hamba.avro", 
+				"fields":[
+					{"name": "a", "type": "string"}
+				]
+			}`)
+
+	r := avro.MustParse(`{
+				"type":"record", "name":"test", "namespace": "org.hamba.avro", 
+				"fields":[
+					{"name": "a", "type": "string"},
+					{"name": "b", "type": "int", "default": 10},
+					{"name": "c", "type": "string", "default": "foo"}
+				]
+			}`)
+
+	type TestW struct {
+		A string `avro:"a"`
+	}
+	value := TestW{A: "abc"}
+
+	b, err := avro.Marshal(w, value)
+	assert.NoError(t, err)
+
+	schema, err := avro.NewSchemaCompatibility().Resolve(r, w)
+	assert.NoError(t, err)
+
+	type TestR struct {
+		A string `avro:"a"`
+		C string `avro:"c"`
+	}
+	want := TestR{A: "abc", C: "foo"}
+
+	var result TestR
+	err = avro.Unmarshal(schema, b, &result)
+	assert.NoError(t, err)
+
+	assert.Equal(t, want, result)
+}
Repository: hamba/avro
Pull request #499 (2025-02-05 15:52:45)

fix(gen): fix multiline doc comments in generated struct
Current generator fails to generate valid Go code in case doc string contains newlines. This PR fixes this issue


Patch:
diff --git a/gen/gen.go b/gen/gen.go
index 010fc85..386be69 100644
--- a/gen/gen.go
+++ b/gen/gen.go
@@ -437,6 +437,7 @@ func (g *Generator) Write(w io.Writer) error {
 			"upperCamel": strcase.ToPascal,
 			"camel":      strcase.ToCamel,
 			"snake":      strcase.ToSnake,
+			"replace":    strings.Replace,
 		}).
 		Parse(g.template)
 	if err != nil {
diff --git a/gen/output_template.tmpl b/gen/output_template.tmpl
index 9d6d59c..f631cf0 100644
--- a/gen/output_template.tmpl
+++ b/gen/output_template.tmpl
@@ -1,6 +1,6 @@
 // Code generated by avro/gen. DO NOT EDIT.
 {{- if len .PackageDoc }}
-// {{ .PackageDoc }}
+// {{ replace .PackageDoc "\n" "\n// " -1 }}
 {{- end }}
 package {{ .PackageName }}
 
@@ -15,7 +15,7 @@ package {{ .PackageName }}
 
 {{- range .Typedefs }}
 	{{- if len .Doc }}
-	// {{ .Doc }}
+	// {{ replace .Doc "\n" "\n// " -1 }}
 	{{- else }}
 	// {{ .Name }} is a generated struct.
 	{{- end }}	
@@ -23,7 +23,7 @@ package {{ .PackageName }}
 	{{- range .Fields }}
 		{{- $f := . }}
 		{{- if len $f.Doc }}
-		// {{ $f.Doc }}
+		// {{ replace $f.Doc "\n" "\n// " -1 }}
 		{{- end }}
 		{{ .Name }} {{ .Type }} `avro:"{{ $f.AvroFieldName }}"
 		{{- range $tag, $style := .Tags }}


Test patch:
diff --git a/gen/gen_test.go b/gen/gen_test.go
index cceede1..0e5f62b 100644
--- a/gen/gen_test.go
+++ b/gen/gen_test.go
@@ -75,6 +75,31 @@ func TestStruct_HandlesGoInitialisms(t *testing.T) {
 	assert.Contains(t, lines, "type HTTPRecord struct {")
 }
 
+func TestStruct_MultilineDoc(t *testing.T) {
+	schema := `{
+  "type": "record",
+  "name": "Test",
+  "doc": "Test record doc\nMultiline record comments",
+  "fields": [
+    { "name": "someString", "type": "string", "doc": "Test field doc\nMultiline field comments" }
+  ]
+}`
+	gc := gen.Config{
+		PackageName: "Something",
+	}
+
+	_, lines := generate(t, schema, gc)
+
+	for _, expected := range []string{
+		"// Test record doc",
+		"// Multiline record comments.",
+		"// Test field doc",
+		"// Multiline field comments.",
+	} {
+		assert.Contains(t, lines, expected)
+	}
+}
+
 func TestStruct_HandlesAdditionalInitialisms(t *testing.T) {
 	schema := `{
   "type": "record",
Repository: hamba/avro
Pull request #500 (2025-02-05 20:39:39)

fix(gen): escape backticks
There is a problem when generating Go code with encoders and full schema. If The schema has some backticks in doc string, then it will produce invalid Go code, because the schema JSON string is wrapped in backticks (``` ` ```). This needs backtick escaping.


Patch:
diff --git a/gen/output_template.tmpl b/gen/output_template.tmpl
index f631cf0..ff36cd6 100644
--- a/gen/output_template.tmpl
+++ b/gen/output_template.tmpl
@@ -39,7 +39,7 @@ package {{ .PackageName }}
 	}
 
 	{{- if $encoders }}
-		var schema{{ .Name }} = avro.MustParse(`{{ .Schema }}`)
+		var schema{{ .Name }} = avro.MustParse(`{{ replace .Schema "`" "` + \"`\" + `" -1 }}`)
 
 		// Schema returns the schema for {{ .Name }}.
 		func (o *{{ .Name }}) Schema() avro.Schema {


Test patch:
diff --git a/gen/gen_test.go b/gen/gen_test.go
index 0e5f62b..e9f5915 100644
--- a/gen/gen_test.go
+++ b/gen/gen_test.go
@@ -100,6 +100,30 @@ func TestStruct_MultilineDoc(t *testing.T) {
 	}
 }
 
+func TestStruct_EscapeBacktick(t *testing.T) {
+	schema := `{
+  "type": "record",
+  "name": "Test",
+  "doc": "Test record doc with ` + "`" + `backticks` + "`" + `",
+  "fields": [
+    { "name": "someString", "type": "string" }
+  ]
+}`
+	gc := gen.Config{
+		PackageName: "Something",
+		Encoders:    true,
+		FullSchema:  true,
+	}
+
+	_, lines := generate(t, schema, gc)
+
+	for _, expected := range []string{
+		"var schemaTest = avro.MustParse(`{\"name\":\"Test\",\"doc\":\"Test record doc with ` + \"`\" + `backticks` + \"`\" + `\",\"type\":\"record\",\"fields\":[{\"name\":\"someString\",\"type\":\"string\"}]}`)",
+	} {
+		assert.Contains(t, lines, expected)
+	}
+}
+
 func TestStruct_HandlesAdditionalInitialisms(t *testing.T) {
 	schema := `{
   "type": "record",
Repository: hamba/avro
Pull request #554 (2025-07-16 09:06:17)

Add schema info bytes method
## Goal of this PR

Add a helper method to the SchemaInfo object that returns the bytes of a schema ID.

## How did I test it?

Added a unit test that verifies whether a high schema ID gets transformed int othe expected byte slice.


Patch:
diff --git a/registry/client.go b/registry/client.go
index e2fdd29..80b358b 100644
--- a/registry/client.go
+++ b/registry/client.go
@@ -7,6 +7,7 @@ package registry
 import (
 	"bytes"
 	"context"
+	"encoding/binary"
 	"fmt"
 	"io"
 	"net"
@@ -121,6 +122,13 @@ type SchemaInfo struct {
 	Metadata SchemaMetadata
 }
 
+// IDBytes returns 4 bytes that represent the schema ID.
+func (s SchemaInfo) IDBytes() []byte {
+	result := make([]byte, 4)
+	binary.BigEndian.PutUint32(result, uint32(s.ID))
+	return result
+}
+
 // SchemaMetadata represents the schema metadata.
 type SchemaMetadata struct {
 	Properties map[string]string


Test patch:
diff --git a/registry/client_test.go b/registry/client_test.go
index 33be708..7929d36 100644
--- a/registry/client_test.go
+++ b/registry/client_test.go
@@ -26,6 +26,16 @@ func TestNewClient_UrlError(t *testing.T) {
 	assert.Error(t, err)
 }
 
+func TestSchemaInfo_IDBytes(t *testing.T) {
+	schemaInfo := registry.SchemaInfo{
+		ID: 123456789,
+	}
+
+	idBytes := schemaInfo.IDBytes()
+
+	assert.Equal(t, []byte{7, 91, 205, 21}, idBytes)
+}
+
 func TestClient_PopulatesError(t *testing.T) {
 	s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 		w.Header().Add("Content-Type", "application/vnd.schemaregistry.v1+json")