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

More descriptive exception in serialize_property #16098

Merged
merged 4 commits into from May 10, 2024

Conversation

kvthr
Copy link
Contributor

@kvthr kvthr commented May 1, 2024

Description

Fixes #15156

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

@kvthr kvthr requested a review from a team as a code owner May 1, 2024 09:01
Copy link

github-actions bot commented May 1, 2024

PR is now waiting for a maintainer to take action.

Note for the maintainer: Commands available:

  • /run-acceptance-tests - used to test run the acceptance tests for the project
  • /run-codegen - used to test the Pull Request against downstream codegen
  • /run-docs-gen - used to test the Pull Request against documentation generation

@kvthr
Copy link
Contributor Author

kvthr commented May 1, 2024

Hey @Frassle! Can I get a review?

@pulumi-bot
Copy link
Contributor

pulumi-bot commented May 1, 2024

Changelog

[uncommitted] (2024-05-09)

Bug Fixes

  • [sdk/python] Provide more descriptive exception

Comment on lines 332 to 333
resource_obj=None,
property_key=None,
Copy link
Member

Choose a reason for hiding this comment

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

Should these really ever be None?
I'd think it should either be
A) Yes, some places call serialize_property and we're not in a resource and/or don't have key. In which case the raise ValueError on line 587 need to handle all those cases [obj&key, just obj, just key, neither].
B) No, everywhere should be able to pass obj and/or key and so they shouldn't default to None and shouldn't be typed as Optionals.

Copy link
Member

Choose a reason for hiding this comment

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

Might be just one or the other for the above. Like maybe everywhere can pass "key" and it should just be of type string and not have a default, but resource really does need to be optional and default to None. Might be both need to be optional, might be neither.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! I tried passing both as positional arguments, just as you said we are calling the function in some places without any Resource and also we need to pass "key" and "object" in all the function call in that case. So I tried =None for defaults.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In conclusion, do we want resource object default as None and "key" as Optional?

Copy link
Member

Choose a reason for hiding this comment

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

also we need to pass "key" and "object" in all the function call in that case.

Yeh, that might be needed. I suspect "key" is needed in nearly (maybe all) call sites.

I'd probably lean on not making them defaults to start. Seeing how many places have sensible key/obj values to pass down, if any don't have a key/obj then make that property an Optional (but without a default), then if most of the callsites used None then clean it up by giving it a default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it!

Copy link

github-actions bot commented May 6, 2024

PR is now waiting for a maintainer to take action.

Note for the maintainer: Commands available:

  • /run-acceptance-tests - used to test run the acceptance tests for the project
  • /run-codegen - used to test the Pull Request against downstream codegen
  • /run-docs-gen - used to test the Pull Request against documentation generation

@kvthr
Copy link
Contributor Author

kvthr commented May 6, 2024

Hi @Frassle, made changes

  • Made resource Optional and default to None and removed default for property
  • As we thought we needed to make changes to a lot of function calls

@@ -581,7 +659,9 @@ async def serialize_property(

# Ensure that we have a value that Protobuf understands.
if not isLegalProtobufValue(value):
raise ValueError(f"unexpected input of type {type(value).__name__}")
raise ValueError(
f"unexpected input of type {type(value).__name__} for {property_key} in {type(resource_obj).__name__}"
Copy link
Member

Choose a reason for hiding this comment

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

property_key and resource_obj might be None. This error needs to handle that otherwise we'll get "for None in None" which doesn't read great.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Apologies, I missed this

Yes, some places call serialize_property and we're not in a resource and/or don't have key. In which case the raise ValueError on line 587 need to handle all those cases [obj&key, just obj, just key, neither].

Copy link

github-actions bot commented May 9, 2024

PR is now waiting for a maintainer to take action.

Note for the maintainer: Commands available:

  • /run-acceptance-tests - used to test run the acceptance tests for the project
  • /run-codegen - used to test the Pull Request against downstream codegen
  • /run-docs-gen - used to test the Pull Request against documentation generation

@Frassle Frassle added this pull request to the merge queue May 10, 2024
Merged via the queue into pulumi:master with commit 086a75d May 10, 2024
8 of 9 checks passed
@justinvp justinvp mentioned this pull request May 10, 2024
@kvthr kvthr deleted the better-error-msg-python branch May 11, 2024 12:22
github-merge-queue bot pushed a commit that referenced this pull request May 13, 2024
Tentative changelog:

### Bug Fixes

- [engine] Fix dataraces between snapshot and deployment systems.
  [#16148](#16148)

- [cli/display] Fix mangled diffs of strings containing url-encoded
chars
  [#16147](#16147)

- [sdk/nodejs] Don't load punycode module in function serialization code
  [#16149](#16149)

- [sdk/nodejs] Return error in RPC response instead of exiting in the
language runtime
  [#16162](#16162)

- [sdk/nodejs] Return the underlying error if we can't locate the pulumi
SDK
  [#16160](#16160)

- [sdk/python] Provide more descriptive exception
  [#16098](#16098)

- [sdk/python] Fix typings for `from_input` and `all` to not return
`Never` types.
  [#16139](#16139)

- [sdk/python] Fix a race condition in output handling
  [#16155](#16155)


### Miscellaneous

- [pkg] Upgrade pulumi-java to v0.11.0
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.

Need better error messages for python when property values are the wrong type.
3 participants