https://pulumi.com logo
#python
Title
# python
g

gorgeous-minister-41131

03/18/2024, 9:37 PM
Anyone get this while trying to access the Output of the ObjectMetaArgs on a CustomResource object metadata property?
Copy code
AttributeError: 'dict' object has no attribute 'name'
Any other resource type seems to return a proper Output[T], but this one returns a dictionary for the
metadata
property.
h

hundreds-gpu-71155

03/18/2024, 9:39 PM
in azure, I usually see this when i call a
get_foo_output()
function--the inner structures on their return tends to be dictionaries instead of objects for some reason
g

gorgeous-minister-41131

03/18/2024, 9:43 PM
this is the k8s provider
This feels like a bug.. this is the closest thing I can find: https://github.com/pulumi/pulumi-kubernetes/issues/1860 but it's not that... what's weird is autonaming works fine...
Copy code
nodeclasses["general"] = k8s.apiextensions.CustomResource(
        "general",
        api_version="karpenter.k8s.aws/v1beta1",
        kind="EC2NodeClass",
        metadata=k8s.meta.v1.ObjectMetaArgs(
            annotations=COMMON_ANNOTATIONS | {"<http://pulumi.com/patchForce|pulumi.com/patchForce>": "true"},
            labels=COMMON_LABELS,
        ),
I would have expected when I reference it,
nodeclasses["general"].metadata.name
, for it to be of type
ObjectMetaArgs
and have access th the Output property,
name
. Instead I'm presented with a 'dict'.
🤷
this breaks my unit testing, because I can't lift the property properly, and now I'll have to do some stupid guard check in my code to trap
KeyError
on it
h

hundreds-gpu-71155

03/18/2024, 9:46 PM
yeah, i wonder if some of the pulumi codegen isn't precise about objects vs dicts
g

gorgeous-minister-41131

03/18/2024, 9:50 PM
Copy code
@property
    @pulumi.getter
    def metadata(self) -> pulumi.Output['_meta.v1.outputs.ObjectMeta']:
        """
        Standard object's metadata. More info: <https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata>
        """
        return pulumi.get(self, "metadata")
so I checked the Namespace, and it imp lements this
but
CustomResource
does not...
this feels like a strange oversight with the codegen for Python but I could be wrong.
I guess I could just extend from CustomResource and implement the method myself for now to save my sanity.