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

[codegen] Fix bug in provider schema where default int properties could not be int #13599

Merged
merged 1 commit into from Jul 27, 2023

Conversation

dixler
Copy link
Contributor

@dixler dixler commented Jul 26, 2023

Description

Fixes #6469

From the issue:

The following type definition

"myprovider:index:ResourceSignal": {
            "properties": {
                "Count": {
                    "type": "integer",
                    "default": 1
                },
                "Timeout": {
                    "type": "string",
                    "default": "PT5M"
                }
            },
            "type": "object"
        }

causes an error during schema import

panic: error importing schema: binding types: failed to bind type myprovider:index:ResourceSignal:
error binding default value for property "Count": invalid default of type int for integer property

Apparently, we only allow floats as defaults here. Changing to 1.0 makes the error go away.

Checklist

  • I have run make tidy to update any new dependencies
  • I have run make lint to verify my code passes the lint check
    • I have formatted my code using gofumpt
  • I have added tests that prove my fix is effective or that my feature works
  • I have run make changelog and committed the changelog/pending/<file> documenting my change
  • Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version

@pulumi-bot
Copy link
Contributor

Changelog

[uncommitted] (2023-07-26)

Bug Fixes

  • [sdkgen] Fix bug binding provider schema where type default int values could not take integers.
    #13599

@dixler dixler marked this pull request as ready for review July 26, 2023 21:06
@dixler dixler requested review from a team and removed request for a team July 26, 2023 21:06
@dixler dixler requested a review from a team July 26, 2023 21:17
}
if math.Trunc(v) != v || v < math.MinInt32 || v > math.MaxInt32 {
if v < math.MinInt32 || v > math.MaxInt32 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check ever needed when v was correctly casted to int from value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. That check takes a float64.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I've written a test case to catch overflows/underflows that failed without it.

Copy link
Contributor

@Zaid-Ajaj Zaid-Ajaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dixler
Copy link
Contributor Author

dixler commented Jul 26, 2023

bors merge

bors bot added a commit that referenced this pull request Jul 26, 2023
13584: [sdkgen/python] SDKgen on external enums r=dixler a=dixler

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Fixes #12695

Python SDKGen was not correctly referencing external enum types which needed an import alias.

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


13599: [codegen] Fix bug in provider schema where default int properties could not be int r=dixler a=dixler

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Fixes #6469

From the issue:

The following type definition

```json
"myprovider:index:ResourceSignal": {
            "properties": {
                "Count": {
                    "type": "integer",
                    "default": 1
                },
                "Timeout": {
                    "type": "string",
                    "default": "PT5M"
                }
            },
            "type": "object"
        }
```

causes an error during schema import

```
panic: error importing schema: binding types: failed to bind type myprovider:index:ResourceSignal:
error binding default value for property "Count": invalid default of type int for integer property
```

Apparently, we only allow floats as defaults here. Changing to `1.0` makes the error go away.

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Kyle Dixler <kyle@pulumi.com>
@bors
Copy link
Contributor

bors bot commented Jul 26, 2023

Build failed (retrying...):

@bors
Copy link
Contributor

bors bot commented Jul 27, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit 39b7166 into master Jul 27, 2023
52 checks passed
@bors bors bot deleted the dixler/6469/codegen-int branch July 27, 2023 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[codegen] Invalid default of type int for integer property
3 participants