Skip to content

Commit b49a16c

Browse files
committed
Add team_id to variable APIs
1 parent 7ab6dc2 commit b49a16c

File tree

17 files changed

+181
-17
lines changed

17 files changed

+181
-17
lines changed

airflow-core/src/airflow/api_fastapi/core_api/datamodels/variables.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from __future__ import annotations
1919

2020
import json
21+
from uuid import UUID
2122

2223
from pydantic import Field, JsonValue, model_validator
2324

@@ -34,6 +35,7 @@ class VariableResponse(BaseModel):
3435
val: str = Field(alias="value")
3536
description: str | None
3637
is_encrypted: bool
38+
team_id: UUID | None
3739

3840
@model_validator(mode="after")
3941
def redact_val(self) -> Self:
@@ -56,6 +58,7 @@ class VariableBody(StrictBaseModel):
5658
key: str = Field(max_length=ID_LEN)
5759
value: JsonValue = Field(serialization_alias="val")
5860
description: str | None = Field(default=None)
61+
team_id: UUID | None = Field(default=None)
5962

6063

6164
class VariableCollectionResponse(BaseModel):

airflow-core/src/airflow/api_fastapi/core_api/openapi/v2-rest-api-generated.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12961,6 +12961,12 @@ components:
1296112961
- type: string
1296212962
- type: 'null'
1296312963
title: Description
12964+
team_id:
12965+
anyOf:
12966+
- type: string
12967+
format: uuid
12968+
- type: 'null'
12969+
title: Team Id
1296412970
additionalProperties: false
1296512971
type: object
1296612972
required:
@@ -13000,12 +13006,19 @@ components:
1300013006
is_encrypted:
1300113007
type: boolean
1300213008
title: Is Encrypted
13009+
team_id:
13010+
anyOf:
13011+
- type: string
13012+
format: uuid
13013+
- type: 'null'
13014+
title: Team Id
1300313015
type: object
1300413016
required:
1300513017
- key
1300613018
- value
1300713019
- description
1300813020
- is_encrypted
13021+
- team_id
1300913022
title: VariableResponse
1301013023
description: Variable serializer for responses.
1301113024
VersionInfo:

airflow-core/src/airflow/api_fastapi/execution_api/datamodels/variable.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ class VariablePostBody(StrictBaseModel):
3434

3535
value: str | None = Field(alias="val")
3636
description: str | None = Field(default=None)
37+
team_id: str | None = Field(default=None)

airflow-core/src/airflow/dag_processing/processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ def _handle_request(self, msg: ToManager, log: FilteringBoundLogger, req_id: int
549549
else:
550550
resp = var
551551
elif isinstance(msg, PutVariable):
552-
self.client.variables.set(msg.key, msg.value, msg.description)
552+
self.client.variables.set(msg.key, msg.value, msg.description, msg.team_id)
553553
elif isinstance(msg, DeleteVariable):
554554
resp = self.client.variables.delete(msg.key)
555555
elif isinstance(msg, GetPreviousDagRun):

airflow-core/src/airflow/models/variable.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def get(
146146
# means SQLA etc is loaded, but we can't avoid that unless/until we add import shims as a big
147147
# back-compat layer
148148

149-
# If this is set it means are in some kind of execution context (Task, Dag Parse or Triggerer perhaps)
149+
# If this is set it means we are in some kind of execution context (Task, Dag Parse or Triggerer perhaps)
150150
# and should use the Task SDK API server path
151151
if hasattr(sys.modules.get("airflow.sdk.execution_time.task_runner"), "SUPERVISOR_COMMS"):
152152
warnings.warn(
@@ -186,6 +186,7 @@ def set(
186186
value: Any,
187187
description: str | None = None,
188188
serialize_json: bool = False,
189+
team_id: str | None = None,
189190
session: Session | None = None,
190191
) -> None:
191192
"""
@@ -197,13 +198,14 @@ def set(
197198
:param value: Value to set for the Variable
198199
:param description: Description of the Variable
199200
:param serialize_json: Serialize the value to a JSON string
201+
:param team_id: ID of the team associated to the variable (if any)
200202
:param session: optional session, use if provided or create a new one
201203
"""
202204
# TODO: This is not the best way of having compat, but it's "better than erroring" for now. This still
203205
# means SQLA etc is loaded, but we can't avoid that unless/until we add import shims as a big
204206
# back-compat layer
205207

206-
# If this is set it means are in some kind of execution context (Task, Dag Parse or Triggerer perhaps)
208+
# If this is set it means we are in some kind of execution context (Task, Dag Parse or Triggerer perhaps)
207209
# and should use the Task SDK API server path
208210
if hasattr(sys.modules.get("airflow.sdk.execution_time.task_runner"), "SUPERVISOR_COMMS"):
209211
warnings.warn(
@@ -219,6 +221,7 @@ def set(
219221
value=value,
220222
description=description,
221223
serialize_json=serialize_json,
224+
team_id=team_id,
222225
)
223226
return
224227

@@ -236,7 +239,7 @@ def set(
236239
ctx = create_session()
237240

238241
with ctx as session:
239-
new_variable = Variable(key=key, val=stored_value, description=description)
242+
new_variable = Variable(key=key, val=stored_value, description=description, team_id=team_id)
240243

241244
val = new_variable._val
242245
is_encrypted = new_variable.is_encrypted
@@ -255,6 +258,7 @@ def set(
255258
val=val,
256259
description=description,
257260
is_encrypted=is_encrypted,
261+
team_id=team_id,
258262
)
259263

260264
# Apply dialect-specific upsert
@@ -264,6 +268,7 @@ def set(
264268
val=val,
265269
description=description,
266270
is_encrypted=is_encrypted,
271+
team_id=team_id,
267272
)
268273
else:
269274
# PostgreSQL and SQLite: ON CONFLICT DO UPDATE
@@ -273,6 +278,7 @@ def set(
273278
val=val,
274279
description=description,
275280
is_encrypted=is_encrypted,
281+
team_id=team_id,
276282
),
277283
)
278284

airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6502,6 +6502,18 @@ export const $VariableBody = {
65026502
}
65036503
],
65046504
title: 'Description'
6505+
},
6506+
team_id: {
6507+
anyOf: [
6508+
{
6509+
type: 'string',
6510+
format: 'uuid'
6511+
},
6512+
{
6513+
type: 'null'
6514+
}
6515+
],
6516+
title: 'Team Id'
65056517
}
65066518
},
65076519
additionalProperties: false,
@@ -6555,10 +6567,22 @@ export const $VariableResponse = {
65556567
is_encrypted: {
65566568
type: 'boolean',
65576569
title: 'Is Encrypted'
6570+
},
6571+
team_id: {
6572+
anyOf: [
6573+
{
6574+
type: 'string',
6575+
format: 'uuid'
6576+
},
6577+
{
6578+
type: 'null'
6579+
}
6580+
],
6581+
title: 'Team Id'
65586582
}
65596583
},
65606584
type: 'object',
6561-
required: ['key', 'value', 'description', 'is_encrypted'],
6585+
required: ['key', 'value', 'description', 'is_encrypted', 'team_id'],
65626586
title: 'VariableResponse',
65636587
description: 'Variable serializer for responses.'
65646588
} as const;

airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,7 @@ export type VariableBody = {
15881588
key: string;
15891589
value: JsonValue;
15901590
description?: string | null;
1591+
team_id?: string | null;
15911592
};
15921593

15931594
/**
@@ -1606,6 +1607,7 @@ export type VariableResponse = {
16061607
value: string;
16071608
description: string | null;
16081609
is_encrypted: boolean;
1610+
team_id: string | null;
16091611
};
16101612

16111613
/**

0 commit comments

Comments
 (0)