databricks-sdk-go
                                
                                 databricks-sdk-go copied to clipboard
                                
                                    databricks-sdk-go copied to clipboard
                            
                            
                            
                        [ISSUE] `AlertOptionsEmptyResultState.Set` doesn't accept empty value
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
Related TF PR: https://github.com/databricks/terraform-provider-databricks/pull/2724
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.