Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ballerina configurable doesn't support fields with nil type #37045

Closed
indikasampath2000 opened this issue Jul 18, 2022 · 3 comments · Fixed by #37268
Closed

Ballerina configurable doesn't support fields with nil type #37045

indikasampath2000 opened this issue Jul 18, 2022 · 3 comments · Fixed by #37268
Assignees
Labels
Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Improvement
Milestone

Comments

@indikasampath2000
Copy link
Contributor

indikasampath2000 commented Jul 18, 2022

Description:
An example code snippet.

type MySQLConnection record {|
    string? user = ();
    string? password = ();
|}; 

configurable MySQLConnection conn = ?;

This gives,

configurable variable currently not supported for '(indikas/ConfigTest:0.1.0:MySQLConfig & readonly)'
	union member type '()' is not supported(BCE3970)

Describe your problem(s)
The above issue is affecting all ballerinax connector config parameters. When a developer wants to set a config record as configurable, it gives the above error. Let me take ballerinax/salesforce connector as an example.

salesforce:init

public isolated function init(ConnectionConfig salesforceConfig) returns Error? {
}

salesforce:ConnectionConfig

public type ConnectionConfig record {|
    string baseUrl;
    http:OAuth2RefreshTokenGrantConfig|http:BearerTokenConfig clientConfig;
    http:ClientSecureSocket secureSocketConfig?;
    string httpVersion = "1.1";
    http:ClientHttp1Settings http1Settings = {};
    http:ClientHttp2Settings http2Settings = {};
    decimal timeout = 60;
    string forwarded = "disable";
    http:FollowRedirects? followRedirects = ();
    http:PoolConfiguration? poolConfig = ();
    http:CacheConfig cache = {};
    http:Compression compression = http:COMPRESSION_AUTO;
    http:CircuitBreakerConfig? circuitBreaker = ();
    http:RetryConfig? retryConfig = ();
    http:CookieConfig? cookieConfig = ();
    http:ResponseLimitConfigs responseLimits = {};
|};

There were two issues I have identified.

  1. In the above record, the http:CookieConfig has an object type called PersistentCookieHandler. Ballerina configurable doesn't support object types. We can remove http:CookieConfig from all ballerinax connector init records as it is not required. But what if a user wanted to create a configurable to initialize ballerina/http connector init (string url, *ClientConfiguration config)?
  2. The following set of records has nil types.
http:ClientHttp1Settings http1Settings = {};
http:ClientHttp2Settings http2Settings = {};
http:FollowRedirects? followRedirects = ();
http:PoolConfiguration? poolConfig = ();
http:CircuitBreakerConfig? circuitBreaker = ();
http:RetryConfig? retryConfig = ();
http:CookieConfig? cookieConfig = ();
http:ClientSecureSocket? secureSocket = ();

I am working on a design to create connections for connectors. This issue is affecting coming up with a clean approach. Appreciate your input.

Describe your solution(s)

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

@MaryamZi MaryamZi added the Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime label Jul 18, 2022
@indikasampath2000
Copy link
Contributor Author

@HindujaB Did you get a chance to discuss this with the team?

@HindujaB
Copy link
Contributor

HindujaB commented Jul 26, 2022

  1. As per the configurable spec, the variable should be an anydata type. So, we restrict this at the compile time if it is a non-anydata type.
    To support this kind of configuration,
    IMO, it is better to have simple configurable variables with only values that need configuration and create the ConnectionConfig record at the init() using the configured values.
    Several connectors are currently using this approach.
    https://github.com/ballerina-platform/module-ballerinax-microsoft.teams/blob/0f3f132fe5973ed977bf0eb35aa2906b92b59821/teams/samples/delete_channel.bal#L25

  2. We don't support the nil type in configurable variables as we can't represent the nil values in the TOML configuration. (In TOML, not providing a value is considered null - In favor of NULL toml-lang/toml#146.)

But, from the above use-cases, we should be able to support the following record fields.

type MySQLConnection record {|
    string? user = ();
    string? password = ();
|}; 

configurable MySQLConnection conn = ?;

Only cases where the field is provided with a default value. This can be done as an improvement.
#28098

As a workaround, we can use optional fields instead of the nilable fields to get similar behavior. But, the limitation is that we can't have a default value for those fields.

public type ConnectionConfig record {|
    string baseUrl;
    http:OAuth2RefreshTokenGrantConfig|http:BearerTokenConfig clientConfig;
    http:ClientSecureSocket secureSocketConfig?;
    string httpVersion = "1.1";
    http:ClientHttp1Settings http1Settings = {};
    http:ClientHttp2Settings http2Settings = {};
    decimal timeout = 60;
    string forwarded = "disable";
    http:FollowRedirects followRedirects?;
    http:PoolConfiguration poolConfig?;
    http:CacheConfig cache = {};
    http:Compression compression = http:COMPRESSION_AUTO;
    http:CircuitBreakerConfig circuitBreaker?;
    http:RetryConfig retryConfig?;
    // http:CookieConfig cookieConfig?; // non-anydata
    http:ResponseLimitConfigs responseLimits = {};
|};

@warunalakshitha
Copy link
Contributor

warunalakshitha commented Jul 26, 2022

I think we should able to support above use case where we have a configurable variable with union type including nil and default value. In that case restrictions of TOML syntax will not an effect. Since nil is part of anydata it is also comply with the spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Improvement
Projects
Archived in project
Status: jBallerina Runtime
Development

Successfully merging a pull request may close this issue.

4 participants