Skip to content

Extra null fields sent in POST requests when resource contains an empty object field #13201

@SarahFrench

Description

@SarahFrench

Affected Resource(s)

  • google_*

Background

What kind of contribution is this issue about?

  • MMv1-based resource

Related PR(s), if any:

Details

Some APIs require a fields in a POST request payload to be an empty object. Until recently this wasn't possible to do, as validation of api.yaml files would assert that NestedObjects need to have at least one property defined.

This PR #6616 introduced the ability to define empty objects. In api.yaml you need to set properties: [] to bypass the validation error described above (along with setting send_empty_value and allow_empty_object to true).

This PR #6872 used the new feature and found a (benign) issue: when the empty object isn't included in the config the field is still sent in the payload of a POST request with a null value. This doesn't cause issues with the API in this particular PR, but it could change in future.

Example

Copy of this comment from the second PR:

If deidentify_template.deidentify_config.record_transformations.field_transformations.primitive_transformation.redact_config is set in the google_data_loss_prevention_deidentify_template resource config then the redactConfig field is present and contains an empty object in the payload:

{
	"deidentifyTemplate": {
		"deidentifyConfig": {
			"recordTransformations": {
				"fieldTransformations": [{
					...
					"primitiveTransformation": {
						"redactConfig": {} ,
					}
				}]
			}
		},
	...
	}
}

If deidentify_template.......primitive_transformation.replace_config is set in the google_data_loss_prevention_deidentify_template resource config and redact_config is absent from the config then the redactConfig field is still present by has a null value in the payload:

{
	"deidentifyTemplate": {
		"deidentifyConfig": {
			"recordTransformations": {
				"fieldTransformations": [{
					...
					"primitiveTransformation": {
						"redactConfig": null,
						"replaceConfig": {
							"newValue": {
								"stringValue": "foobar"
							}
						}
					}
				}]
			}
		},
		...
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    mmv1-generatorProvider-wide changes to resource templates or other generator changespersistent-bugHard to diagnose or long lived bugs for which resolutions are more like feature work than bug workservice/terraformsize/mtechnical-debt

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions