mirror of
https://github.com/luthermonson/go-proxmox.git
synced 2026-04-26 17:35:48 +03:00
[GH-ISSUE #209] omitempty for boolean values prevent false from being sent to API endpoint #59
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/go-proxmox#59
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kernel-sanders on GitHub (Aug 15, 2025).
Original GitHub issue: https://github.com/luthermonson/go-proxmox/issues/209
When using
omitemptyon abool, the value will be omitted if it isfalsesincefalseis the "zero value" of abool. This is expected behavior (see https://github.com/golang/go/issues/13284).Issues arise when the Proxmox default for a
boolfield is1ortrueas it is not possible to send an explicitly0orfalsedue to theomitemptyflag on the json marshaler.Example - Creating an API Token without privilege separation
This creates an API token for a user, but privilege separation is enabled, which is the default for the Proxmox API.
Potential Solutions
There are two ways I see to handle this:
omitemptyflags fromboolvalues*boolas the value, as it effectively is a ternary (nil, true, or false).Option 1 is probably the simplest solution, and I'll open a PR that accomplishes it.
Affected API Calls
I've looked through the codebase and this error likely effects the following API calls:
1. User Creation and Updates, API Token Creation
NewUserEnable bool `json:"enable,omitempty"`/access/users, the API defaults to creating the user in an enabled state (enable=1). If you try to create a user that is disabled from the start by settingEnable: false, the field will be omitted, and Proxmox will create an enabled user anyway.UserEnable IntOrBool `json:"enable,omitempty"`PUT /access/users/{userid}. If you want to disable an active user by settingEnable: false, theomitemptytag will cause the field to be dropped from the request. Since the API does not receive theenableparameter, it makes no change, and the user remains enabled.TokenPrivsep IntOrBool `json:"privsep,omitempty"`privsep=1). If you try to create an API key with privilege separation disabled by settingPivsep: false, the field will be omitted, and Proxmox will create an API token with privilege separation enabled anyway.2. Access Control Lists (ACLs)
ACL(used when updating ACLs)Propagate IntOrBooljson:"propagate,omitempty"`propagateoption defaults to1(true), meaning the permissions apply to child objects in the hierarchy. If you want to create a permission that applies only to the specified path and not its children (Propagate: false), the field will be omitted, and the API will default to enabling propagation.3. Domain Management
DomainVerify IntOrBool `json:"verify,omitempty"`verifyoption (to verify the server's TLS certificate) defaults to1(true). If you are in a test environment and need to disable this verification by settingVerify: false, the field will be omitted from the request, and the API will enforce certificate verification by default, likely causing the connection to fail.4. Storage and Downloads
StorageDownloadURLOptionsVerifyCertificates IntOrBool `json:"verify-certificates,omitempty"`Domain.Verifyissue. When downloading an ISO or template from a URL, the API defaults to verifying the remote server's TLS certificate (verify-certificates=1). To download from a source with a self-signed certificate, you would need to setVerifyCertificates: false. Due toomitempty, this is not possible, as the field will be dropped and the API will default totrue.5. Virtual Machine Backups (
vzdump)VirtualMachineBackupOptionsRemove bool `json:"remove,omitempty"`removeflag in the backup API controls whether the temporary lock on a VM is removed after the backup completes. It defaults to1(true). In certain scripting scenarios, you might want to keep the VM locked after a backup (Remove: false). This is impossible because setting it tofalsecauses it to be omitted, and the API defaults to removing the lock.VirtualMachineBackupOptionsStdExcludes bool `json:"stdexcludes,omitempty"`1(true). If you had a specific need to include these temporary file systems in your backup by settingStdExcludes: false, the field would be omitted, and the API would default to excluding them.