Coverage for /home/airflow/.local/lib/python3.12/site-packages/airflow/api_fastapi/core_api/datamodels/trigger.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 14:22 +0000

1# Licensed to the Apache Software Foundation (ASF) under one 

2# or more contributor license agreements. See the NOTICE file 

3# distributed with this work for additional information 

4# regarding copyright ownership. The ASF licenses this file 

5# to you under the Apache License, Version 2.0 (the 

6# "License"); you may not use this file except in compliance 

7# with the License. You may obtain a copy of the License at 

8# 

9# http://www.apache.org/licenses/LICENSE-2.0 

10# 

11# Unless required by applicable law or agreed to in writing, 

12# software distributed under the License is distributed on an 

13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 

14# KIND, either express or implied. See the License for the 

15# specific language governing permissions and limitations 

16# under the License. 

17from __future__ import annotations 

18 

19from datetime import datetime 

20from typing import Annotated 

21 

22from pydantic import BeforeValidator, ConfigDict, Field 

23 

24from airflow.api_fastapi.core_api.base import BaseModel 

25 

26 

27def _remove_kwargs(_: object) -> str: 

28 """ 

29 Return empty trigger kwargs for API responses. 

30 

31 Trigger ``kwargs`` may contain sensitive values (for example credentials a deferred 

32 operator hands to its trigger -- an API key, a token), so they are never exposed through 

33 the REST API. The field is kept in the response schema for backwards compatibility -- so 

34 existing API consumers do not break on a missing property -- but it is always returned 

35 empty, as ``"{}"`` (the stringified empty dict, matching the string format the field has 

36 always used). The triggerer still decrypts and uses the real kwargs at runtime; only the 

37 API representation is emptied. 

38 """ 

39 return "{}" 

40 

41 

42class TriggerResponse(BaseModel): 

43 """Trigger serializer for responses.""" 

44 

45 model_config = ConfigDict(populate_by_name=True) 

46 

47 id: int 

48 classpath: str 

49 # Deprecated: always emptied (see ``_remove_kwargs``). Marked deprecated in the schema so 

50 # consumers are nudged off it. ``deprecated`` only warns on direct attribute access, not 

51 # during model serialization, so our own response rendering stays warning-free. 

52 kwargs: Annotated[str, BeforeValidator(_remove_kwargs), Field(deprecated=True)] 

53 created_date: datetime 

54 queue: str | None 

55 triggerer_id: int | None