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
[sdkgen/python] Fix referencing local types with a different package name #12669
Conversation
Changelog[uncommitted] (2023-04-17)Bug Fixes
|
15af5e7
to
29abd6a
Compare
The Python SDK generator wasn't correctly referencing types that have a different package name in their type token than the name of the schema's package (which is the case when embedding k8s CRD resources/types in a package). This change fixes the generator to emit these local references correctly.
29abd6a
to
2db264a
Compare
@@ -791,9 +790,6 @@ func (mod *modContext) importObjectType(t *schema.ObjectType, input bool) string | |||
} | |||
|
|||
importPath := mod.getRelImportFromRoot() | |||
if mod.pkg.Name() != parts[0] { |
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.
Note that we handle external imports at the start of the method:
pulumi/pkg/codegen/python/gen.go
Lines 776 to 778 in 44f2064
if !codegen.PkgEquals(t.PackageReference, mod.pkg) { | |
return fmt.Sprintf("import %s", pyPack(t.PackageReference.Name())) | |
} |
What I'm removing seems to be leftover from a previous attempt to support this, which is causing the problems.
import pulumi.runtime | ||
from typing import Any, Mapping, Optional, Sequence, Union, overload | ||
from . import _utilities | ||
from . import crd_k8s_amazonaws_com as _crd_k8s_amazonaws_com |
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.
We now import here correctly.
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.
Generated Python code looks valid, and existing Python code hasn't changed.
bors merge |
Build succeeded:
|
The Python SDK generator wasn't correctly referencing types that have a different package name in their type token than the name of the schema's package (which is the case when embedding k8s CRD resources/types in a package). This change fixes the generator to emit these local references correctly.
Fixes #12624