databricks-sdk-go icon indicating copy to clipboard operation
databricks-sdk-go copied to clipboard

[ISSUE] `AlertOptionsEmptyResultState.Set` doesn't accept empty value

Open alexott opened this issue 2 years ago • 2 comments

Description

For AlertOptionsEmptyResultState enum we have the following helper function to convert a string value into enum value.

func (f *AlertOptionsEmptyResultState) Set(v string) error {
	switch v {
	case `ok`, `triggered`, `unknown`:
		*f = AlertOptionsEmptyResultState(v)
		return nil
	default:
		return fmt.Errorf(`value "%s" is not one of "ok", "triggered", "unknown"`, v)
	}
}

It right now accepts only specific values, but because the corresponding field in the Options is marked as omitempty, then the empty value is also acceptable.

Reproduction

calling .Set("") on an instance of AlertOptionsEmptyResultState results in the error message that "" value isn't allowed.

As result, in Terraform I need to write:

	if a.Options.EmptyResultState != "" {
		err = ca.Options.EmptyResultState.Set(a.Options.EmptyResultState)
	}

instead of simple (without if):

err = ca.Options.EmptyResultState.Set(a.Options.EmptyResultState)

Expected behavior

.Set("") should work without error

Debug Logs The SDK logs helpful debugging information when debug logging is enabled. Set the log level to Trace by configuring the default logger to log at trace (for example: add logger.DefaultLogger = &logger.SimpleLogger{Level: logger.LevelTrace} to your program), and include the logs here.

Other Information

  • OS: [e.g. macOS]
  • Version: 0.20.0

alexott avatar Sep 26 '23 13:09 alexott

Related TF PR: https://github.com/databricks/terraform-provider-databricks/pull/2724

alexott avatar Sep 26 '23 13:09 alexott

This is interesting. It might be "safe" to allow users to set a field explicitly to an empty value. The issue is that whether a field is optional or not in a structure is independent of whether the enumeration supports an empty value, but enums in the Go SDK are modeled as strings and thus are always empty string for a new request structure, even if empty string is not a valid value for that enum. https://github.com/databricks/databricks-sdk-go/pull/724 is a WIP pr exploring this idea.

mgyucht avatar Nov 30 '23 15:11 mgyucht