[sdkgen/python] Fix error calling _configure when the value is None (#14014)
We recently fixed an issue where defaults weren't set for nested objects
when the nested objects are passed as dicts (#13825). Unfortunately,
this introduced a regression when the nested object is optional, but it
itself has required fields, and the nested object is not specified. In
that case, an unintended error is raised.
Consider a `Provider` resource with an optional `certmanager:
ProviderCertmanagerArgs` argument, which itself has two required
properties: `mtls_cert_pem` and `mtls_key_pem`.
When creating a new `Provider` without specifying a `certmanager`, we
get an error:
```
TypeError: ProviderCertmanagerArgs._configure() missing 2 required positional arguments: 'mtls_cert_pem' and 'mtls_key_pem'
```
The source of the problem is this check in the generated `Provider`'s
constructor:
```python
if not isinstance(certmanager, ProviderCertmanagerArgs):
certmanager = certmanager or {}
def _setter(key, value):
certmanager[key] = value
ProviderCertmanagerArgs._configure(_setter, **certmanager)
```
When `certmanager` is not specified, its value is `None`, which is also
not an instance of `ProviderCertmanagerArgs`. So the code inside the
`if` executes. `ProviderCertmanagerArgs._configure` is called on an
empty dict, and the error is raised because there are two required
positional arguments to `ProviderCertmanagerArgs._configure`.
The fix is to add an additional check to ensure the value is not `None`.
Fixes #14012
2023-09-22 18:28:25 +00:00
|
|
|
{
|
|
|
|
"version": "0.0.1",
|
|
|
|
"name": "foo",
|
|
|
|
"provider": {
|
|
|
|
"inputProperties": {
|
|
|
|
"certmanager": {
|
|
|
|
"$ref": "#/types/foo:index:ProviderCertmanager"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"types": {
|
|
|
|
"foo:index:ProviderCertmanager": {
|
|
|
|
"properties": {
|
2024-02-05 10:42:32 +00:00
|
|
|
"mtlsCertPem": {
|
[sdkgen/python] Fix error calling _configure when the value is None (#14014)
We recently fixed an issue where defaults weren't set for nested objects
when the nested objects are passed as dicts (#13825). Unfortunately,
this introduced a regression when the nested object is optional, but it
itself has required fields, and the nested object is not specified. In
that case, an unintended error is raised.
Consider a `Provider` resource with an optional `certmanager:
ProviderCertmanagerArgs` argument, which itself has two required
properties: `mtls_cert_pem` and `mtls_key_pem`.
When creating a new `Provider` without specifying a `certmanager`, we
get an error:
```
TypeError: ProviderCertmanagerArgs._configure() missing 2 required positional arguments: 'mtls_cert_pem' and 'mtls_key_pem'
```
The source of the problem is this check in the generated `Provider`'s
constructor:
```python
if not isinstance(certmanager, ProviderCertmanagerArgs):
certmanager = certmanager or {}
def _setter(key, value):
certmanager[key] = value
ProviderCertmanagerArgs._configure(_setter, **certmanager)
```
When `certmanager` is not specified, its value is `None`, which is also
not an instance of `ProviderCertmanagerArgs`. So the code inside the
`if` executes. `ProviderCertmanagerArgs._configure` is called on an
empty dict, and the error is raised because there are two required
positional arguments to `ProviderCertmanagerArgs._configure`.
The fix is to add an additional check to ensure the value is not `None`.
Fixes #14012
2023-09-22 18:28:25 +00:00
|
|
|
"type": "string"
|
|
|
|
},
|
2024-02-05 10:42:32 +00:00
|
|
|
"mtlsKeyPem": {
|
[sdkgen/python] Fix error calling _configure when the value is None (#14014)
We recently fixed an issue where defaults weren't set for nested objects
when the nested objects are passed as dicts (#13825). Unfortunately,
this introduced a regression when the nested object is optional, but it
itself has required fields, and the nested object is not specified. In
that case, an unintended error is raised.
Consider a `Provider` resource with an optional `certmanager:
ProviderCertmanagerArgs` argument, which itself has two required
properties: `mtls_cert_pem` and `mtls_key_pem`.
When creating a new `Provider` without specifying a `certmanager`, we
get an error:
```
TypeError: ProviderCertmanagerArgs._configure() missing 2 required positional arguments: 'mtls_cert_pem' and 'mtls_key_pem'
```
The source of the problem is this check in the generated `Provider`'s
constructor:
```python
if not isinstance(certmanager, ProviderCertmanagerArgs):
certmanager = certmanager or {}
def _setter(key, value):
certmanager[key] = value
ProviderCertmanagerArgs._configure(_setter, **certmanager)
```
When `certmanager` is not specified, its value is `None`, which is also
not an instance of `ProviderCertmanagerArgs`. So the code inside the
`if` executes. `ProviderCertmanagerArgs._configure` is called on an
empty dict, and the error is raised because there are two required
positional arguments to `ProviderCertmanagerArgs._configure`.
The fix is to add an additional check to ensure the value is not `None`.
Fixes #14012
2023-09-22 18:28:25 +00:00
|
|
|
"type": "string"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"required": [
|
2024-02-05 10:42:32 +00:00
|
|
|
"mtlsCertPem",
|
|
|
|
"mtlsKeyPem"
|
[sdkgen/python] Fix error calling _configure when the value is None (#14014)
We recently fixed an issue where defaults weren't set for nested objects
when the nested objects are passed as dicts (#13825). Unfortunately,
this introduced a regression when the nested object is optional, but it
itself has required fields, and the nested object is not specified. In
that case, an unintended error is raised.
Consider a `Provider` resource with an optional `certmanager:
ProviderCertmanagerArgs` argument, which itself has two required
properties: `mtls_cert_pem` and `mtls_key_pem`.
When creating a new `Provider` without specifying a `certmanager`, we
get an error:
```
TypeError: ProviderCertmanagerArgs._configure() missing 2 required positional arguments: 'mtls_cert_pem' and 'mtls_key_pem'
```
The source of the problem is this check in the generated `Provider`'s
constructor:
```python
if not isinstance(certmanager, ProviderCertmanagerArgs):
certmanager = certmanager or {}
def _setter(key, value):
certmanager[key] = value
ProviderCertmanagerArgs._configure(_setter, **certmanager)
```
When `certmanager` is not specified, its value is `None`, which is also
not an instance of `ProviderCertmanagerArgs`. So the code inside the
`if` executes. `ProviderCertmanagerArgs._configure` is called on an
empty dict, and the error is raised because there are two required
positional arguments to `ProviderCertmanagerArgs._configure`.
The fix is to add an additional check to ensure the value is not `None`.
Fixes #14012
2023-09-22 18:28:25 +00:00
|
|
|
],
|
|
|
|
"type": "object"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"language": {
|
|
|
|
"python": {}
|
|
|
|
}
|
|
|
|
}
|