fix(controlplane): rewrite stored contracts with a null spec to `spec: {}`

Merged
JA
18d ago
+175-2

Since v1.135.3, the control plane and the CLI reject a YAML contract that has an empty spec: line:

v2 Contract format error: error unmarshalling raw message: :6:6 spec: value is required (required)

The cause is the update of buf.build/go/protoyaml from v0.7.0 to v0.8.0 (#3816). protoyaml v0.8.0 leaves a message field unset when its YAML value is null (bufbuild/protoyaml-go#72). v0.7.0 set an empty message.

The v0.8.0 behavior is the correct one: in the protobuf JSON mapping, null for a message field means "not set", and protojson already rejected "spec": null. So we keep it, and we update the stored data instead.

This change adds a migration that rewrites the null top-level spec of stored YAML contracts (spec:, spec: null or spec: ~) to spec: {}. This keeps the meaning of the stored text, and the control plane and the CLI can read these contracts again. It also uses spec: {} in the empty contract example of the docs, which had an empty spec:.

Behavior

Contract textUp to v1.135.2v1.135.3 and v1.135.4With this change
Stored with spec:, spec: null or spec: ~valid, empty specinvalid on each readrewritten to spec: {}, valid
New, with spec:validinvalidinvalid
New, with spec: {}validvalidvalid
JSON with "spec": nullinvalidinvalidinvalid

Migration

  • It changes only rows with the yaml format, and only a null spec at the top level of the document. A spec with fields, a nested spec key and JSON rows do not change.
  • It keeps a comment on the spec: line and the line endings of the document.
  • It skips a row that is not valid UTF-8, so the migration cannot fail on such a row.
  • A second run changes nothing.
  • raw_body is immutable in the application. The migration changes the stored text of past contract revisions, but it does not change what they mean.

FAQ

Why not keep the v0.7.0 behavior in the parser?
It is not correct by the protobuf JSON mapping, and it is not consistent with JSON. We can keep the strict parser if we update the stored data once.

What must users do?
Update the control plane, so that the migration runs. A contract file that a user keeps in a repository with an empty spec: is now rejected on create and update: change it to spec: {}. The release notes must say this.

Do CLI v1.135.3 and v1.135.4 still fail?
No. They parse the contract that the control plane sends, and after the migration that text has spec: {}.

This change was made with AI assistance (Claude Code).