Skip to content

bug: Go empty values are invalidly serialized as null instead of empty values. #17118

@bjornrobertsson

Description

@bjornrobertsson

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Go empty values are invalidly serialized as null instead of empty values. Consider the following snippet:

$ echo '{"field": "groups"}' | coder organization settings set org-sync
{
    "field": "groups",
    "mapping": null,
    "organization_assign_default": false
}

And in the UI we get "Can't convert null to object"

We can see that if we don't explicitly set the mapping field, it ends up being null instead of {}. This breaks the JavaScript client side.

Workaround:
A workaround right now is to explicitly set mapping to an empty value:

echo '{"field": "groups", "mapping": {}}' | coder organization settings set org-sync

The real solution is to convert empty Go maps to empty JSON objects instead of null.

The IdP sync settings for an organization have the same problem.

Additional Context: May have a similar cause as #16988

Relevant Log Output

Expected Behavior

Missing entities, either null or {} should not cause fatal errors or should be automatically mapped to {} instead

Steps to Reproduce

  1. Create an 'null' group by using the org-sync function (https://coder.com/docs/reference/cli/organizations_settings_show_organization-sync)
  • echo '{"field": "groups"}' | coder organization settings set org-sync

Environment

  • Host OS:
  • Coder version:

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    s2Broken use cases or features (with a workaround). Only humans may set this.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions