You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Metadata models report null instead of [] for empty lists (push referenceAsTags, pull files) #2169
Two metadata models emit null instead of [] when their list is empty. The other list-carrying models initialise to an empty slice, so the same template or JSON consumer behaves differently depending on the command.
never initialised; Files() returns slices.Clone(nil)
null
oras push with no tag
model.NewPush builds referenceAsTags with var refAsTags []string and only appends, so an untagged push marshals it as null:
{ "referenceAsTags": null }
A go-template taking its length fails outright:
$ oras push localhost:5000/repo file.txt --format go-template='{{len .referenceAsTags}}'Error: template: format output:1:2: executing "format output" at <len .referenceAsTags>:error calling len: len of nil pointer
The same shape works for oras repo tags --format go-template='{{len .tags}}' and oras repo ls --format go-template='{{len .repositories}}'.
oras pull with no titled layer
PullHandler.OnFilePulled is only called for layers carrying org.opencontainers.image.title (cmd/oras/root/pull.go), so pulling an artifact with no titled layer leaves Pulled.files nil, and Files() returns slices.Clone(nil), which is also nil. "files" then marshals as null.
{{range .files}} — what the e2e suite uses — tolerates either form, which is why this has gone unnoticed. {{len .files}} does not.
Proposal
Initialise both to an empty slice so empty lists are always []. For push this is a one-line change:
- var refAsTags []string+ refAsTags := make([]string, 0, len(tags))
I'll open a PR for push with regression tests at the model, JSON-handler and template-handler levels. pull is the same root cause in model/pull.go; happy to fold it into the same PR or do it separately, whichever you prefer. (#2002 touches that file, but only its import block.)
Nothing in the repository asserts on null here: the JSON push test compares with slices.Equal, which treats nil and empty alike, and the e2e suite only ranges over both fields.
For anyone finding this later: this issue covered two halves, and it auto-closed when #2170 merged because I used a closing keyword in that PR while it deliberately fixed only the push half (referenceAsTags).
The remaining pull half — files marshalling as null when a pull produces no files, which also makes {{len .files}} fail — is now addressed in #2175.
Activity
akshita317 commentedon Sep 19, 2026
For anyone finding this later: this issue covered two halves, and it auto-closed when #2170 merged because I used a closing keyword in that PR while it deliberately fixed only the
pushhalf (referenceAsTags).The remaining
pullhalf —filesmarshalling asnullwhen a pull produces no files, which also makes{{len .files}}fail — is now addressed in #2175.