Repository navigation
fix(display): report referenceAsTags as [] instead of null when untagged - #2170
Merged
TerryHowe merged 2 commits intoSep 18, 2026
Merged
Conversation
model.NewPush built referenceAsTags with `var refAsTags []string` and only
appended to it, so an untagged push marshalled the field as null. A
go-template taking its length then failed:
error calling len: len of nil pointer
The other list fields in the metadata models -- repositories for repo ls,
tags for repo tags and referrers for discover -- are all initialised to an
empty slice and report [], so the same template shape worked for those
commands but not for push.
Initialise the slice with make([]string, 0, len(tags)) so an empty list
marshals as [], preallocating it to its final length.
Add regression tests at each layer the value passes through, each confirmed
to fail before this change:
- model: NewPush marshals referenceAsTags as [] for nil and empty tags,
comparing the raw JSON so null and [] are told apart
- json handler: an untagged Render reports referenceAsTags as []
- template handler: {{len .referenceAsTags}} renders 0 after an untagged
push instead of erroring
For an untagged `oras push --format json` the field changes from null to [].
Nothing in the repository depended on null: the existing JSON push test
compares with slices.Equal, which treats nil and empty alike, and the e2e
suite only ranges over the field.
pull's files field has the same root cause and is tracked in the same
issue; it is left for a separate change.
Refs oras-project#2169
Signed-off-by: Akshita <[email protected]>
akshita317
requested review from
TerryHowe,
Wwwsylvia,
sabre1041,
sajayantony and
shizhMSFT
as code owners
September 14, 2026 16:05
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2170 +/- ##
==========================================
+ Coverage 87.71% 87.78% +0.07%
==========================================
Files 139 139
Lines 5689 5689
==========================================
+ Hits 4990 4994 +4
+ Misses 419 415 -4
Partials 280 280 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
TerryHowe
reviewed
Sep 18, 2026
Signed-off-by: Terry Howe <[email protected]>
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2169 (the
pushhalf).Problem
model.NewPushbuiltreferenceAsTagswithvar refAsTags []stringand only appended, so an untagged push marshalled it asnull:{ "referenceAsTags": null }and a go-template taking its length failed outright:
repo ls(repositories),repo tags(tags) anddiscover(referrers) all initialise to an empty slice and report[], so the same template shape worked for those commands but not forpush. Confirmed in review of #2164.Fix
Empty now marshals as
[], and the slice is preallocated to its final length.Tests
Regression tests at each layer the value passes through, all written first and confirmed failing on
main:mainmodelTestNewPush_referenceAsTags(nil / empty / 1 / 2 tags)referenceAsTags = null, want []jsonTestPushHandler_Render_untaggedreferenceAsTags = null, want []templateTestPushHandler_Render_untaggedLen({{len .referenceAsTags}})len of nil pointerThe model test compares the raw JSON value, so it distinguishes
nullfrom[]rather than accepting either. The existing tagged-push assertions are unchanged and still pass.Compatibility
For an untagged
oras push --format json,referenceAsTagschanges fromnullto[], matching the other list fields. Nothing in the repository depended onnull: the existing JSON push test compares withslices.Equal, which treats nil and empty alike, and the e2e suite only ranges over the field.go test ./...,gofmtandgo vetare clean.Not in this PR
pull'sfileshas the same root cause (see #2169) and lives inmodel/pull.go. I've kept this PR topushas discussed; happy to follow up withpullseparately or add it here, whichever you prefer.