Repository: bacalhau-project/bacalhau (language: python)

Issue:
Fix marshalling of request structures
Request structures used by the V2 client emit all fields when serializing to JSON.
They need to omit the same fields as are emitted from query


Discussion / hints:

Fix patch:
diff --git a/pkg/publicapi/apimodels/base_requests.go b/pkg/publicapi/apimodels/base_requests.go
index 7410bd1503..0d6d670b34 100644
--- a/pkg/publicapi/apimodels/base_requests.go
+++ b/pkg/publicapi/apimodels/base_requests.go
@@ -7,7 +7,7 @@ import (
 // BaseRequest is the base request used for all requests
 type BaseRequest struct {
 	Namespace string            `query:"namespace"`
-	Headers   map[string]string `query:"-"`
+	Headers   map[string]string `query:"-" json:"-"`
 
 	// A good place to define other fields that are common to all requests,
 	// such as auth tokens


Test patch:
diff --git a/pkg/publicapi/apimodels/base_requests_test.go b/pkg/publicapi/apimodels/base_requests_test.go
new file mode 100644
index 0000000000..5dc1ba0b1b
--- /dev/null
+++ b/pkg/publicapi/apimodels/base_requests_test.go
@@ -0,0 +1,43 @@
+//go:build unit || !integration
+
+package apimodels_test
+
+import (
+	"encoding/json"
+	"testing"
+
+	"github.com/bacalhau-project/bacalhau/pkg/publicapi/apimodels"
+	"github.com/stretchr/testify/suite"
+)
+
+type BaseRequestTestCase struct {
+	suite.Suite
+}
+
+func TestBaseRequestSuite(t *testing.T) {
+	suite.Run(t, new(BaseRequestTestCase))
+}
+
+func (s *BaseRequestTestCase) TestBaseRequest() {
+	initial := apimodels.BasePutRequest{
+		BaseRequest: apimodels.BaseRequest{
+			Namespace: "namespace",
+			Headers: map[string]string{
+				"test": "test",
+			},
+		},
+		IdempotencyToken: "1234",
+	}
+
+	b, err := json.Marshal(initial)
+	s.Require().NoError(err)
+
+	var result apimodels.BasePutRequest
+	err = json.Unmarshal(b, &result)
+	s.Require().NoError(err)
+
+	// Should not contain any headers from the TestBaseRequest
+	s.Require().Empty(result.Headers, "headers were not excluded from json marshalling")
+	s.Require().Equal(initial.Namespace, result.Namespace, "namespace was not marshalled correctly")
+	s.Require().Equal(initial.IdempotencyToken, result.IdempotencyToken, "idempotency token was not marshalled correctly")
+}