Skip to content

Scope GetTemplateByName/GetIsoByName by-ID lookup to the zone (#87)#153

Open
jmsperu wants to merge 1 commit into
apache:mainfrom
jmsperu:fix/template-byname-zoneid
Open

Scope GetTemplateByName/GetIsoByName by-ID lookup to the zone (#87)#153
jmsperu wants to merge 1 commit into
apache:mainfrom
jmsperu:fix/template-byname-zoneid

Conversation

@jmsperu

@jmsperu jmsperu commented Jun 20, 2026

Copy link
Copy Markdown

Fixes #87.

Problem

GetTemplateByName resolves the template id with the zoneid constraint (via GetTemplateID), but then calls GetTemplateByID without it:

id, count, err := s.GetTemplateID(name, templatefilter, zoneid, opts...)
...
r, count, err := s.GetTemplateByID(id, templatefilter, opts...)   // zone dropped

A template registered in multiple zones lists one row per zone for the same UUID, so the by-id lookup returns count > 1 and the helper fails:

There is more then one result for Template UUID: 06145677-058a-456a-89a0-af4afd6fffcf!

GetIsoByName has the identical issue.

Fix

These helpers are generated, so the fix is in the generator (generate/generate.go): for Template/Iso, pass the zone into the by-ID lookup using the existing WithZone option, then apply it to the two generated helpers:

r, count, err := s.GetTemplateByID(id, templatefilter, append(opts, WithZone(zoneid))...)

WithZone is a no-op when zoneid is empty and sets the id directly when given a UUID (no extra lookup), so this is safe and adds no API calls.

Test

Adds test/GetTemplateByNameZoneRegression_test.go: the mock returns two rows for the unscoped by-id lookup and one when zoneid is present. It fails with the exact There is more then one result error on current main and passes with the fix.

Verification

)

GetTemplateByName (and GetIsoByName) resolve the id with the zoneid
constraint via GetTemplateID, then call GetTemplateByID/GetIsoByID WITHOUT
the zone. A template/ISO registered in multiple zones lists one row per
zone for the same UUID, so the helper fails with 'There is more then one
result for Template UUID: ...!' (apache#87).

Fix the generator to pass the zone into the by-ID lookup via the existing
WithZone option for Template/Iso, and apply it to the two generated helpers.
WithZone is a no-op on empty zoneid and uses the id directly for a UUID.
Adds a regression test reproducing apache#87.

Signed-off-by: James Peru <james@xcobean.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GetTemplateByName with zoneid constraint fails on template in multiple zones

1 participant