sparse-carpenter-66912
04/07/2025, 9:36 AMpyflyte run
command the missing env-vars with --env my-var="hello" --env my-var-2="reader"
. This fails with the following error:
Request rejected by the API, due to Invalid input.
RPC Failed, with Status: StatusCode.INVALID_ARGUMENT
Details: src.workflows.run_pipeline.pipeline workflow with different structure already exists. (Please register a new version of the workflow):
1. How do I fix this?
2. Is there an easier way to give environmental variables to a workflow? best case would be to give a .env
-filejolly-florist-66728
04/07/2025, 9:36 AMpyflyte register
to register the updated workflow version.
2. Passing Environment Variables: Flyte tasks can be configured to use environment variables by specifying them in the task definition. According to Flyte documentation, you can specify environment variables directly in the task using the environment
parameter in the @task
decorator. For example:
from flytekit import task
@task(environment={"MY_ENV_VAR": "my_value"})
def my_task() -> str:
import os
return os.environ["MY_ENV_VAR"]
If you want to use a .env
file, you can load the environment variables in your Python script before running the workflow. Use a library like python-dotenv
to load the variables:
from dotenv import load_dotenv
import os
load_dotenv() # Load environment variables from a .env file
@task
def my_task() -> str:
return os.environ["MY_ENV_VAR"]
Would you like more detail on any of these steps?
Sources:
- Flyte Environment Variables 👍 0 button 👎 1 button 💡 Hint: Mention @ancient-wolf-19325 in the thread for followups.sparse-carpenter-66912
04/07/2025, 9:55 AMpyflyte register
runs successfully, but how do I run the newly registered workflow? Do I just run pyflyte run
again? Because here I receive the same error again.
2. I actually (try to) load the env-vars via pydantic-settings
in the workflow definition, but when running these do not seem to be setjolly-florist-66728
04/07/2025, 9:55 AMpyflyte register
, you should run it using the pyflyte run
command with the --remote
flag to ensure it executes on the Flyte cluster. This command will use the latest registered version of the workflow. Here's an example:
pyflyte run --remote --project <your_project> --domain <your_domain> <path_to_your_workflow_file> <workflow_name>
Ensure that the project and domain match those used during registration.
2. Loading Environment Variables with Pydantic: If you're using pydantic-settings
to load environment variables, ensure that the environment variables are set in the environment where the Flyte tasks are executed. Flyte tasks run in isolated environments, so environment variables need to be explicitly set in the task configuration or loaded within the task using a library like python-dotenv
. Here's an example of how you can load environment variables within a task:
from pydantic import BaseSettings
from flytekit import task
class Settings(BaseSettings):
my_var: str
my_var_2: str
@task
def my_task() -> str:
settings = Settings()
return f"{settings.my_var} {settings.my_var_2}"
Ensure that the environment variables are available in the task's execution environment, either by setting them in the task definition or by loading them from a .env
file.
Would you like more detail on any of these steps?
Sources:
- https://github.com/flyteorg/flyte/blob/master/docs/user_guide/flyte_fundamentals/running_and_scheduling_workflows.md
- https://github.com/flyteorg/flyte/issues/4503 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.sparse-carpenter-66912
04/07/2025, 1:37 PM