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/python] Fix incorrect ObjectType name generated under tfbridge20 compat #10935

Merged
merged 5 commits into from Oct 6, 2022

Conversation

t0yv0
Copy link
Member

@t0yv0 t0yv0 commented Oct 5, 2022

Description

Python codegen gets confused about which modContext a given ObjectType belongs to, which may result in dangling type references being generated (when incorrect typeDetails being looked up for the ObjectType).

This PR comes from investigating user-reported pulumi/pulumi-terraform-bridge#611 although it does not in itself completely solve it.

The minified example has the following:

  • a function is declared

  • one of the supplemental types in this function comes from a different module in the same package (by mistake - to fix Inclusion of a / in a datasources module name produces incorrect tokens in schema.json for children properties pulumi-terraform-bridge#611 this needs to change also), which is supported in theory

  • function code is generated thinking this supplemental type belongs to module "x/iam" module

  • but the type itself is generated thinking it belongs to "x" module

  • the modContext for "x/iam" and "x" do not agree on "typeDetails", which under "tfbridge20" compatibility influences type name generation; therefore the code generates a dangling type reference _x.outputs.GetPolicyDocumentStatement where _x.outputs.GetPolicyDocumentStatementResult is expected

Fixes # (issue)

Checklist

  • 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 Service API version

@t0yv0 t0yv0 force-pushed the t0yv0/pulumi-terraform-bridge-611 branch from d23f916 to 83d2a04 Compare October 5, 2022 19:36
@pulumi-bot
Copy link
Contributor

pulumi-bot commented Oct 5, 2022

Changelog

[uncommitted] (2022-10-05)

Bug Fixes

  • [sdkgen/python] Fixes dangling type-refs generated under compatibility=tfbridge20 for schemas that refer to types aross modules.
    #10935

Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -2766,6 +2783,22 @@ func generateModuleContextMap(tool string, pkg *schema.Package, info PackageInfo
mod.extraSourceFiles = append(mod.extraSourceFiles, p)
}

// Setup modLocator so that mod.typeDetails finds the right
// modContext for every ObjectType.
modLocator := &modLocator{
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why we need the extra struct here instead of just passing a handle to the func

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking in case it needs more methods later like EnumType, and I also like to have my obj.method() syntax to have an idea what the call is doing, but yeah technically could just have been func.

@t0yv0
Copy link
Member Author

t0yv0 commented Oct 6, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Oct 6, 2022

Build succeeded:

@bors bors bot merged commit a8705a4 into master Oct 6, 2022
@bors bors bot deleted the t0yv0/pulumi-terraform-bridge-611 branch October 6, 2022 13:44
iwahbe pushed a commit that referenced this pull request Oct 10, 2022
10935: [codegen/python] Fix incorrect ObjectType name generated under tfbridge20 compat r=t0yv0 a=t0yv0

<!--- 
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

Python codegen gets confused about which modContext a given ObjectType belongs to, which may result in dangling type references being generated (when incorrect typeDetails being looked up for the ObjectType).

This PR comes from investigating user-reported pulumi/pulumi-terraform-bridge#611 although it does not in itself completely solve it. 

The minified example has the following:

- a function is declared

- one of the supplemental types in this function comes from a different module in the same package (by mistake - to fix pulumi/pulumi-terraform-bridge#611 this needs to change also), which is supported in theory

- function code is generated thinking this supplemental type belongs to module "x/iam" module

- but the type itself is generated thinking it belongs to "x" module

- the modContext for "x/iam" and "x" do not agree on "typeDetails", which under "tfbridge20" compatibility influences type name generation; therefore the code generates a dangling type reference `_x.outputs.GetPolicyDocumentStatement` where `_x.outputs.GetPolicyDocumentStatementResult` is expected


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

Fixes # (issue)

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] 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 Service,
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 Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Anton Tayanovskyy <anton@pulumi.com>
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.

Inclusion of a / in a datasources module name produces incorrect tokens in schema.json for children properties
3 participants