o-nikolas commented on code in PR #58905:
URL: https://github.com/apache/airflow/pull/58905#discussion_r2583007480


##########
airflow-core/src/airflow/secrets/environment_variables.py:
##########
@@ -33,11 +33,16 @@ class EnvironmentVariablesBackend(BaseSecretsBackend):
     def get_conn_value(self, conn_id: str) -> str | None:
         return os.environ.get(CONN_ENV_PREFIX + conn_id.upper())
 
-    def get_variable(self, key: str) -> str | None:
+    def get_variable(self, key: str, team_id: str | None = None) -> str | None:
         """
         Get Airflow Variable from Environment Variable.
 
         :param key: Variable Key
+        :param team_id: ID of the team associated to the task trying to access 
the variable (if any)
         :return: Variable Value
         """
+        if team_id and (team_var := 
os.environ.get(f"{VAR_ENV_PREFIX}_{team_id.upper()}__" + key.upper())):
+            # Format to set a team specific variable: 
AIRFLOW_VAR__<TEAM_ID>__<VAR_KEY>

Review Comment:
   > This is really not convenient for the user to use the team ID in the env 
variable
   
   Completely agree, from a user perspective, I think we need to allow them to 
provide team_name here. It is what is used for the team airflow configuration 
right now, so it would also be confusing if that was different.
   
    > I do not think either we should make a request here to get the team name 
associated to the team ID
   
   Is it that expensive? Can we cache the results so that we aren't requesting 
the same mapping multiple times?



##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/variables.py:
##########
@@ -62,7 +62,9 @@ def delete_variable(
     session: SessionDep,
 ):
     """Delete a variable entry."""
-    if Variable.delete(variable_key, session) == 0:
+    result = session.execute(delete(Variable).where(Variable.key == 
variable_key))
+    rows = getattr(result, "rowcount", 0) or 0
+    if rows == 0:

Review Comment:
   Curious why this change, is this more sqla 1-->2?



##########
providers/amazon/src/airflow/providers/amazon/aws/secrets/secrets_manager.py:
##########
@@ -225,11 +225,12 @@ def get_conn_value(self, conn_id: str) -> str | None:
             return standardized_secret
         return secret
 
-    def get_variable(self, key: str) -> str | None:
+    def get_variable(self, key: str, team_id: str | None = None) -> str | None:

Review Comment:
   Is the implementation that uses this new param going to come in another PR?



##########
airflow-core/src/airflow/secrets/environment_variables.py:
##########
@@ -33,11 +33,16 @@ class EnvironmentVariablesBackend(BaseSecretsBackend):
     def get_conn_value(self, conn_id: str) -> str | None:
         return os.environ.get(CONN_ENV_PREFIX + conn_id.upper())
 
-    def get_variable(self, key: str) -> str | None:
+    def get_variable(self, key: str, team_id: str | None = None) -> str | None:
         """
         Get Airflow Variable from Environment Variable.
 
         :param key: Variable Key
+        :param team_id: ID of the team associated to the task trying to access 
the variable (if any)
         :return: Variable Value
         """
+        if team_id and (team_var := 
os.environ.get(f"{VAR_ENV_PREFIX}_{team_id.upper()}__" + key.upper())):
+            # Format to set a team specific variable: 
AIRFLOW_VAR__<TEAM_ID>__<VAR_KEY>

Review Comment:
   Also note that AIP-67 called for a triple underscore after the team name for 
exporting airflow config, we should probably do the same for variables?
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to