Skip to content

Commit

Permalink
put back _ZRB_EXECUTION_ID into forbidden name
Browse files Browse the repository at this point in the history
  • Loading branch information
goFrendiAsgard committed Nov 5, 2023
1 parent 94a9d9a commit 54746b7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/zrb/task/base_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
)
from zrb.advertisement import advertisements
from zrb.task_group.group import Group
from zrb.task_env.constant import RESERVED_ENV_NAMES
from zrb.task_env.env import Env
from zrb.task_env.env_file import EnvFile
from zrb.task_input.any_input import AnyInput
Expand Down Expand Up @@ -282,6 +283,8 @@ def _get_all_envs(self) -> Mapping[str, Env]:
self._allow_add_env_files = False
all_envs: Mapping[str, Env] = {}
for env_name in os.environ:
if env_name in RESERVED_ENV_NAMES:
continue
all_envs[env_name] = Env(
name=env_name, os_name=env_name, renderable=False
)
Expand Down
7 changes: 4 additions & 3 deletions src/zrb/task/docker_compose_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from zrb.task.any_task_event_handler import (
OnTriggered, OnWaiting, OnSkipped, OnStarted, OnReady, OnRetry, OnFailed
)
from zrb.task_env.constant import RESERVED_ENV_NAMES
from zrb.task_env.env import Env
from zrb.task_env.env_file import EnvFile
from zrb.task_group.group import Group
Expand Down Expand Up @@ -187,18 +188,18 @@ def _get_all_envs(self) -> Mapping[str, Env]:
# compose envs
data = read_compose_file(self._compose_template_file)
env_map = fetch_compose_file_env_map(data)
registered_env_map: Mapping[str, bool] = {}
added_env_map: Mapping[str, bool] = {}
for key, value in env_map.items():
# Need to get this everytime because we only want
# the first compose file env value for a certain key
if key in registered_env_map:
if key in RESERVED_ENV_NAMES or key in added_env_map:
continue
os_name = key
if self._compose_env_prefix != '':
os_name = f'{self._compose_env_prefix}_{os_name}'
compose_env = Env(name=key, os_name=os_name, default=value)
additional_envs.append(compose_env)
registered_env_map[key] = True
added_env_map[key] = True
# Add additional envs and addition env files to this task
self._envs = additional_envs + list(self._envs)
self._env_files = additional_env_files + list(self._env_files)
Expand Down
1 change: 1 addition & 0 deletions src/zrb/task_env/constant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RESERVED_ENV_NAMES = ('_ZRB_EXECUTION_ID',)
3 changes: 3 additions & 0 deletions src/zrb/task_env/env.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from zrb.helper.typing import Optional
from zrb.helper.typecheck import typechecked
from zrb.task_env.constant import RESERVED_ENV_NAMES
import os


Expand All @@ -16,6 +17,8 @@ def __init__(
default: str = '',
renderable: bool = True,
):
if name in RESERVED_ENV_NAMES:
raise ValueError(f'Forbidden input name: {name}')
self.name: str = name
self.os_name: str = os_name if os_name is not None else name
self.default: str = default
Expand Down
3 changes: 3 additions & 0 deletions src/zrb/task_env/env_file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from zrb.helper.typing import List, Optional
from zrb.helper.typecheck import typechecked
from dotenv import dotenv_values
from zrb.task_env.constant import RESERVED_ENV_NAMES
from zrb.task_env.env import Env


Expand All @@ -25,6 +26,8 @@ def get_envs(self) -> List[Env]:
env_list: List[Env] = []
env_map = dotenv_values(self.env_file)
for key, value in env_map.items():
if key in RESERVED_ENV_NAMES:
continue
os_name: Optional[str] = None
if self.prefix is not None and self.prefix != '':
os_name = f'{self.prefix}_{key}'
Expand Down

0 comments on commit 54746b7

Please sign in to comment.