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
Conversation
d23f916
to
83d2a04
Compare
Changelog[uncommitted] (2022-10-05)Bug Fixes
|
There was a problem hiding this 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{ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
bors r+ |
Build succeeded: |
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>
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 inschema.json
for children properties pulumi-terraform-bridge#611 this needs to change also), which is supported in theoryfunction 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 expectedFixes # (issue)
Checklist
make changelog
and committed thechangelog/pending/<file>
documenting my change