Skip to content

Conversation

@ottramst
Copy link

Summary

This PR changes two Policy fields in the Go client.

Rationale: with omitempty on non-pointer booleans, an explicit false is dropped from JSON, which prevents API callers from intentionally setting false. Moving to *bool enables proper tri-state behavior:

  • nil → field omitted (server default applies)
  • true → "field": true sent
  • false → "field": false sent

This unblocks providers/clients (e.g., Terraform providers) from sending deterministic values and avoids “inconsistent result after apply” diffs caused by server defaults overriding omitted fields.

Problem

When a caller sets:

p := dtrack.Policy{
  Name: "Example",
  Global:          false, // intended
  IncludeChildren: false, // intended
}

The JSON encoder omits both fields due to omitempty + zero value:

{
  "name": "Example"
}

Servers may default these flags (e.g., global=true), so a subsequent read returns:

{
  "name": "Example",
  "global": true,
  "includeChildren": false
}

Infra tooling (Terraform) then reports:

Provider produced inconsistent result after apply:
.global: was cty.False, but now cty.True

This makes it impossible to reliably set false.

Solution

Change Policy.IncludeChildren and Policy.Global to pointers:

  • Callers who want server defaults: leave as nil.
  • Callers who want explicit values: pass address of a local bool.

@ottramst ottramst requested a review from nscuro as a code owner October 29, 2025 08:30
Copilot AI review requested due to automatic review settings October 29, 2025 08:30
@owasp-dt-bot
Copy link

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR changes the Policy struct's IncludeChildren and Global fields from bool to *bool (boolean pointers), allowing them to be explicitly set to true, false, or omitted (nil). This enables proper JSON serialization/deserialization with the omitempty tag, so these fields are only included in the JSON when explicitly set rather than always including their zero values.

  • Changed field types from bool to *bool in the Policy struct
  • Added comprehensive test coverage for JSON encoding, decoding, and round-trip scenarios
  • Tests verify proper handling of nil, true, and false values for both fields

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
policy.go Modified IncludeChildren and Global fields in Policy struct from bool to *bool
policy_test.go Added comprehensive test suite covering JSON marshaling/unmarshaling with nil and explicit boolean values, including usage of OptionalBoolOf helper function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants