Hi all! Is there a way to fetch workflow informati...
# flyte-support
h
Hi all! Is there a way to fetch workflow information within a task? I know we can flytekit.current_context() but wonder how we can get the workflow information. It is discouraged for us to use fetch_workflow().
t
what are you trying to look up? the currently running workflow?
h
Yup
t
this is definitely information that propeller has but i think it’s maybe not injected into the container.
h
I know I can get the execution id, but how can I get the workflow from execution id without using the flytekit Remote client?
t
to what end might i ask?
also what workflow? (if this is inside a subworkflow which is inside a dynamic task, that constructed the subworkflow and the subworkflow itself doesn’t exist in admin)
h
So the loop is: Before, we will put the GIT_HASH as a env into the image. Now, we migrate to CI to build the image, so we cannot have the GIT_HASH any more. (Hopefully you remember this!) So the way I am trying to do is, get the context by
Copy code
flytekit.current_context().execution_id
And get version by
Copy code
execution = remote.fetch_execution(
                project=execution_id.project, domain=execution_id.domain, name=execution_id.name
            )
            return execution.spec.launch_plan.version
But it is a not very good practice to allow flyte node to access flyte admin proxy...
The way to generate the version is {branch_name}-{git_hash}
t
the goal is to get the launch plan version?
h
So to your question:
also what workflow?
I am not sure what impact would be but in theory, the version should be the same? (workflow vs subworkflow)
t
is launch plan version not the same as the task version?
h
Ah
Will task_version == launch_plan version?
Copy code
launch_plan {
  resource_type: LAUNCH_PLAN
  project: "ml-exploration"
  domain: "adhoc"
  name: "src.python.flyte.ml_exploration.reproducible_example.main.reproducible_example"
  version: "felixm-PYTHON-527-fix-flyte-registration-3190ad1272a7"
}
Copy code
{'_stats': <flytekit.core.mock_stats.MockStats at 0x7fd6d470ad00>,
 '_execution_date': datetime.datetime(2024, 6, 28, 19, 34, 24, 45322),
 '_working_directory': '/tmp/flytef4ztieh4/user_space',
 '_execution_id': project: "local"
 domain: "local"
 name: "local",
 '_logging': <Logger flytekit.user_space (INFO)>,
 '_raw_output_prefix': '/tmp/flyte-bawvan6b/raw',
 '_attrs': {},
 '_secrets_manager': <flytekit.core.context_manager.SecretsManager at 0x7fd6d470a1c0>,
 '_checkpoint': None,
 '_decks': [],
 '_task_id': TASK:local:local:local:local}
t
not necessarily, but it usually is. if you are calling a reference task, then no, it will definitely be different
but in the normal ci flow where you just register a whole bunch of files then yes
why is everything local? that looks like local execution
in a live run, all these should be there
h
I run this in a notebook
in a live run, all these should be there
This works! Thank you Yee!
@thankful-minister-83577 One more question if you happened around: Can I get the task's image uri by an easy way? Like getting from an env above or some other API?
t
no that we haven’t done.
most users have that built into the image itself.
but i’m guessing you can’t do that? chicken and egg type thing?
h
Yup I agree. It is similar to docker image where you cannot query image info within a running container
t
put in a ticket for this?
is this something you’d be willing to contribute to?
h
Sorry was very busy recently. Yeah I can take a look and try to contribute after I wrapped up my current stuff.