Skip to content

[v2] fix(params): allow zero values for required numeric fields - #4014

Merged
mandre merged 3 commits into
v2from
bp-v2-0a0301f-9efd285-bec3ee5
Sep 16, 2026
Merged

mandre merged 3 commits into
v2from
bp-v2-0a0301f-9efd285-bec3ee5

Conversation

@gophercloud-backport-bot

Copy link
Copy Markdown

Backport: #4012

Fixes #3866

Links to the line numbers/files in the OpenStack source code that support the
code in this PR:

Problem

registeredlimits.CreateOpts.DefaultLimit is declared as int with
required:"true", and BuildRequestBody rejects the zero value of any
required field. As a result the SDK fails client-side with Missing input for argument [DefaultLimit] when creating a registered limit with a
default_limit of 0, even though Keystone accepts 0 as a valid limit
(valid range is -1 to 2147483647).

Solution

BuildRequestBody, BuildQueryString, and BuildHeaders no longer treat a numeric zero as missing input for
fields tagged required:"true". Zero is legitimate input for numeric
fields, so range validation is left to the server. Other zero values
(empty strings, nil pointers, empty structs, ...) are still rejected
client-side as before, so existing validation behavior is unchanged
everywhere else.

This implements option 1 suggested by @winiciusallan in the issue,
scoped to numeric kinds so the existing ErrMissingInput expectations
for string/struct/pointer fields keep working.

Validation

  • Added TestBuildRequestBodyRequiredNumericZero (testing/params_test.go):
    required int zero passes and is serialized; required string empty
    still returns ErrMissingInput.
  • Extended TestBuildQueryString and TestBuildHeaders to verify required
    numeric zero values are serialized while other required zero values remain
    rejected.
  • Added TestCreateRegisteredLimitWithZeroDefaultLimit plus fixtures
    (openstack/identity/v3/registeredlimits/testing/): end-to-end create
    with DefaultLimit: 0, asserting the request body sent on the wire.
  • Verified the new test fails before the fix with exactly the reported
    error (Missing input for argument [DefaultLimit]) and passes after.
  • Full unit suite (go test ./...) passes, except the pre-existing
    TestNormalizePathURL failure which also fails on a clean checkout on
    Windows (path/URL normalization, unrelated to this change).
  • go vet is clean on the touched packages, including the acceptance
    test package (-tags acceptance).
  • Extended the TestRegisteredLimitsCRUD acceptance test with a
    default_limit: 0 create/assert/delete block (not run here, requires a
    live OpenStack cloud).

@github-actions github-actions Bot added v2 This PR targets v2 edit:gophercloud This PR updates common Gophercloud code edit:identity This PR updates identity code semver:patch No API change labels Sep 16, 2026
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 64.032% (+0.02%) from 64.015% — bp-v2-0a0301f-9efd285-bec3ee5 into v2

@mandre
mandre merged commit 4994a7d into v2 Sep 16, 2026
18 of 19 checks passed
@mandre
mandre deleted the bp-v2-0a0301f-9efd285-bec3ee5 branch September 16, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

edit:gophercloud This PR updates common Gophercloud code edit:identity This PR updates identity code semver:patch No API change v2 This PR targets v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants