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

warning: most_recent is deprecated: This attribute has no purpose. Output needed? #651

Open
eBeyond opened this issue Dec 6, 2024 · 10 comments
Labels
awaiting/codegen Blocked on a missing bug or feature in SDK generation kind/bug Some behavior is incorrect or out of spec

Comments

@eBeyond
Copy link

eBeyond commented Dec 6, 2024

When running pulumi preview with some servers (using the latest release) I get these outputs:

    /<...>/lib/python3.13/site-packages/pulumi_hcloud/_utilities.py:313: UserWarning: This attribute has no purpose.
      warnings.warn(message)

    warning: most_recent is deprecated: This attribute has no purpose.
    warning: most_recent is deprecated: This attribute has no purpose.
    warning: most_recent is deprecated: This attribute has no purpose.
    warning: most_recent is deprecated: This attribute has no purpose.
    warning: most_recent is deprecated: This attribute has no purpose.
    warning: most_recent is deprecated: This attribute has no purpose.
    warning: most_recent is deprecated: This attribute has no purpose.
    warning: most_recent is deprecated: This attribute has no purpose.
    warning: most_recent is deprecated: This attribute has no purpose.
    warning: most_recent is deprecated: This attribute has no purpose.
    warning: most_recent is deprecated: This attribute has no purpose.
    warning: most_recent is deprecated: This attribute has no purpose.

It's not stopping anything, so it's not a bug. But I don't feel comfortable with that. Do we need this?

I wasn't using most_recent as an attribute. So I think that's something internal.

@pulumi-bot pulumi-bot added the needs-triage Needs attention from the triage team label Dec 6, 2024
@VenelinMartinov VenelinMartinov added kind/bug Some behavior is incorrect or out of spec and removed needs-triage Needs attention from the triage team labels Dec 6, 2024
@VenelinMartinov
Copy link
Contributor

Hi @eBeyond thanks for reporting the issue. This seems to be coming from a deprecation warning in the TF hcloud provider: https://github.com/hetznercloud/terraform-provider-hcloud/blob/cffad666d26a10f1d17fd1450599e14e3492f8da/internal/network/data_source.go#L70

Can you please check if you are using the data source and provide a program which reproduces the warning?

@VenelinMartinov VenelinMartinov added needs-repro Needs repro steps before it can be triaged or fixed awaiting-feedback Blocked on input from the author labels Dec 6, 2024
@eBeyond
Copy link
Author

eBeyond commented Dec 6, 2024

Yes, it's the datasource it's coming from. I create a StackReference to my other stack and get the needed network.
Everytime I retrieve an information from the "core_network" shown below. I get the message mentioned in my ticket. ;)

base_stack = StackReference("my/stack/change")
networks = base_stack.get_output("networks")
core_network = hcloud.get_network(id=networks["core"])
print(core_network.id)

In the example the message is shown, when invoking the last line (print(...))

@pulumi-bot pulumi-bot added needs-triage Needs attention from the triage team and removed awaiting-feedback Blocked on input from the author labels Dec 6, 2024
@VenelinMartinov
Copy link
Contributor

id is an output, so that print statement is unlikely to work. It likely calls the deprecated property under the hood.

Did you mean to use core_network.id.apply(lambda id: print(id)) instead?

See https://www.pulumi.com/docs/iac/concepts/inputs-outputs/apply/#accessing-single-outputs-with-apply for more details

@VenelinMartinov VenelinMartinov added awaiting-feedback Blocked on input from the author and removed needs-repro Needs repro steps before it can be triaged or fixed needs-triage Needs attention from the triage team labels Dec 6, 2024
@eBeyond
Copy link
Author

eBeyond commented Dec 6, 2024

core_network = hcloud.get_network(id=networks["core"])
core_network.id.apply(lambda id: print(id))

would result into:

  error: Program failed with an unhandled exception:
    Traceback (most recent call last):
      File "<...>/core/__main__.py", line 13, in <module>
        core_network.id.apply(lambda id: print(id))
        ^^^^^^^^^^^^^^^^^^^^^
    AttributeError: 'int' object has no attribute 'apply'

@pulumi-bot pulumi-bot added needs-triage Needs attention from the triage team and removed awaiting-feedback Blocked on input from the author labels Dec 6, 2024
@VenelinMartinov
Copy link
Contributor

Ah, my bad, good point, thanks for trying it out!

@VenelinMartinov
Copy link
Contributor

VenelinMartinov commented Dec 6, 2024

@eBeyond the example doesn't repro for me, can you please try upgrading to the latest hcloud provider version and add a self-contained repro of the problem? Are the stack references essential for the issue? Are all stacks using the latest hcloud version?

import pulumi
import pulumi_hcloud as hcloud


def get_network(id_str: str) -> None:
    net = hcloud.get_network(id=int(id_str))
    print(net.id)


core_network = hcloud.Network(
    "core",
    name="core",
    ip_range="10.0.0.0/8",
)

core_network.id.apply(get_network)

@VenelinMartinov VenelinMartinov added needs-repro Needs repro steps before it can be triaged or fixed awaiting-feedback Blocked on input from the author and removed needs-triage Needs attention from the triage team labels Dec 6, 2024
@eBeyond
Copy link
Author

eBeyond commented Dec 8, 2024

import pulumi
import pulumi_hcloud as hcloud

core_network = hcloud.Network(
    "core1",
    name="core1",
    ip_range="10.123.0.0/24",
)

net = hcloud.get_network(id=core_network.id)
pulumi.Output.all(network=net).apply(lambda args: print(args["network"].id))

This produces the following output:

     Type                 Name         Plan     Info
     pulumi:pulumi:Stack  core1-core1           1 warning; 3 messages

Diagnostics:
  pulumi:pulumi:Stack (core1-core1):
    /<...>/python3.13/site-packages/pulumi_hcloud/_utilities.py:313: UserWarning: This attribute has no purpose.
      warnings.warn(message)

    warning: most_recent is deprecated: This attribute has no purpose.

    10433892

Resources:
    2 unchanged

The pulumi.Output.all(...).apply is a commonly used option to process values from multiple outputs.

It seems that the conversion to a dict will also visit the "most_recent" field and that triggers the warning.
I

@pulumi-bot pulumi-bot added needs-triage Needs attention from the triage team and removed awaiting-feedback Blocked on input from the author labels Dec 8, 2024
@iwahbe
Copy link
Member

iwahbe commented Dec 9, 2024

Hi @eBeyond.

From the example you listed, I think the warning is actually coming from the hcloud.get_network call. I don't think the warning should be there, since you never actually use most_recent. The SDK is code generated, so I'll open a bug in the code generator. Sorry for the inconvenience.


P.S. Your example doesn't type-check:

$ pyright 

/Users/iwahbe/Projects/pulumi/langs/python/__main__.py
  /Users/iwahbe/Projects/pulumi/langs/python/__main__.py:10:29 - error: Argument of type "Output[str]" cannot be assigned to parameter "id" of type "int | None" in function "get_network"
    Type "Output[str]" cannot be assigned to type "int | None"
      "Output[str]" is incompatible with "int"
      "Output[str]" is incompatible with "None" (reportGeneralTypeIssues)
1 error, 0 warnings, 0 informations 

I think what you want would look like this:

import pulumi
import pulumi_hcloud as hcloud

core_network = hcloud.Network(
    "core1",
    name="core1",
    ip_range="10.123.0.0/24",
)


net = hcloud.get_network_output(id=core_network.id.apply(int))
net.id.apply(print)

@eBeyond
Copy link
Author

eBeyond commented Dec 9, 2024

Hi,
It's definitively when calling pulumi.Output.all(network=net).apply.
when doing net.id.apply(print) it will break. id is an int and doesn't have an apply().

"""A Python Pulumi program"""
import pulumi
import pulumi_hcloud as hcloud

core_network = hcloud.Network(
    "core1",
    name="core1",
    ip_range="10.123.0.0/24",
)

net = hcloud.get_network(id=core_network.id)
print(f"first print: {net.id}")
pulumi.Output.all(network=net).apply(lambda args: print(f"second print: {args["network"].id}"))

If you comment out the first print. You'll get the warning. If you comment out the second print (the output.all thing), you won't get a warning.
So I expect the issue is with the handling of all()

@iwahbe
Copy link
Member

iwahbe commented Dec 9, 2024

I opened pulumi/pulumi#17965 upstream.

I believe that pulumi.Output.all will generate the warning, but that seems valid to me. most_recent is escaping the context of Pulumi, so we print a warning. The problem I see is that simply calling hcloud.get_network_output(...) will also generate a warning. There is no way to not see the warning.

when doing net.id.apply(print) it will break. id is an int and doesn't have an apply().

hcloud.get_network(id=core_network.id).id.apply(print) will break, since it returns a resolved value. If core_network is a resource (like in your example), then the call doesn't type check. hcloud.get_network_output(id=core_network.id.apply(int)).id.apply(print) does work (note the _output on the function name), since it accepts outputs and returns outputs.

If you comment out the first print. You'll get the warning. If you comment out the second print (the output.all thing), you won't get a warning.
So I expect the issue is with the handling of all()

The problem is not with all. It's just that pulumi.Output.all will await it's values. This also warns:

import pulumi
import pulumi_hcloud as hcloud

core_network = hcloud.Network(
    "core1",
    name="core1",
    ip_range="10.123.0.0/24",
)

async def do(core_network_id: str):
    net = hcloud.get_network(id=int(core_network_id))
    await net

core_network.id.apply(do)

@iwahbe iwahbe removed needs-repro Needs repro steps before it can be triaged or fixed needs-triage Needs attention from the triage team labels Dec 9, 2024
@iwahbe iwahbe added the awaiting/codegen Blocked on a missing bug or feature in SDK generation label Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting/codegen Blocked on a missing bug or feature in SDK generation kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

No branches or pull requests

4 participants