Skip to content

Commit 130e0de

Browse files
committed
Initial implementation of Bulk Patch approach for Connections, replace default for mutable fields and fix a comment, Remove unit test for old method
1 parent 73342f9 commit 130e0de

File tree

11 files changed

+737
-573
lines changed

11 files changed

+737
-573
lines changed

airflow/api_fastapi/core_api/datamodels/connections.py

+71-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from __future__ import annotations
1919

2020
import json
21+
from typing import Any, Literal
2122

2223
from pydantic import Field, field_validator
2324
from pydantic_core.core_schema import ValidationInfo
@@ -90,8 +91,74 @@ class ConnectionBody(BaseModel):
9091
extra: str | None = Field(default=None)
9192

9293

93-
class ConnectionBulkBody(BaseModel):
94-
"""Connections Serializer for requests body."""
94+
class ConnectionBulkCreateAction(BaseModel):
95+
"""Bulk Create Variable serializer for request bodies."""
96+
97+
action: Literal["create"] = "create"
98+
connections: list[ConnectionBody] = Field(..., description="A list of connections to be created.")
99+
action_if_exists: Literal["skip", "overwrite", "fail"] = "fail"
100+
101+
102+
class ConnectionBulkUpdateAction(BaseModel):
103+
"""Bulk Update Connection serializer for request bodies."""
104+
105+
action: Literal["update"] = "update"
106+
connections: list[ConnectionBody] = Field(..., description="A list of connections to be updated.")
107+
action_if_not_exists: Literal["skip", "fail"] = "fail"
95108

96-
connections: list[ConnectionBody]
97-
overwrite: bool | None = Field(default=False)
109+
110+
class ConnectionBulkDeleteAction(BaseModel):
111+
"""Bulk Delete Connection serializer for request bodies."""
112+
113+
action: Literal["delete"] = "delete"
114+
connection_ids: list[str] = Field(..., description="A list of connection IDs to be deleted.")
115+
action_if_not_exists: Literal["skip", "fail"] = "fail"
116+
117+
118+
class ConnectionBulkBody(BaseModel):
119+
"""Request body for bulk Connection operations (create, update, delete)."""
120+
121+
actions: list[ConnectionBulkCreateAction | ConnectionBulkUpdateAction | ConnectionBulkDeleteAction] = (
122+
Field(..., description="A list of Connection actions to perform.")
123+
)
124+
125+
126+
class ConnectionBulkActionResponse(BaseModel):
127+
"""
128+
Serializer for individual bulk action responses.
129+
130+
Represents the outcome of a single bulk operation (create, update, or delete).
131+
The response includes a list of successful connection_ids and any errors encountered during the operation.
132+
This structure helps users understand which key actions succeeded and which failed.
133+
"""
134+
135+
success: list[str] = Field(
136+
default_factory=list, description="A list of connection_ids representing successful operations."
137+
)
138+
errors: list[dict[str, Any]] = Field(
139+
default_factory=list,
140+
description="A list of errors encountered during the operation, each containing details about the issue.",
141+
)
142+
143+
144+
class ConnectionBulkResponse(BaseModel):
145+
"""
146+
Serializer for responses to bulk connection operations.
147+
148+
This represents the results of create, update, and delete actions performed on connections in bulk.
149+
Each action (if requested) is represented as a field containing details about successful connection_ids and any encountered errors.
150+
Fields are populated in the response only if the respective action was part of the request, else are set None.
151+
"""
152+
153+
create: ConnectionBulkActionResponse | None = Field(
154+
default=None,
155+
description="Details of the bulk create operation, including successful connection_ids and errors.",
156+
)
157+
update: ConnectionBulkActionResponse | None = Field(
158+
default=None,
159+
description="Details of the bulk update operation, including successful connection_ids and errors.",
160+
)
161+
delete: ConnectionBulkActionResponse | None = Field(
162+
default=None,
163+
description="Details of the bulk delete operation, including successful connection_ids and errors.",
164+
)

airflow/api_fastapi/core_api/openapi/v1-generated.yaml

+167-22
Original file line numberDiff line numberDiff line change
@@ -1786,50 +1786,49 @@ paths:
17861786
application/json:
17871787
schema:
17881788
$ref: '#/components/schemas/HTTPValidationError'
1789-
/public/connections/bulk:
1790-
put:
1789+
patch:
17911790
tags:
17921791
- Connection
1793-
summary: Put Connections
1794-
description: Create connection entry.
1795-
operationId: put_connections
1792+
summary: Bulk Connections
1793+
description: Bulk create, update, and delete connections.
1794+
operationId: bulk_connections
17961795
requestBody:
1796+
required: true
17971797
content:
17981798
application/json:
17991799
schema:
18001800
$ref: '#/components/schemas/ConnectionBulkBody'
1801-
required: true
18021801
responses:
18031802
'200':
1804-
description: Created with overwrite
1803+
description: Successful Response
18051804
content:
18061805
application/json:
18071806
schema:
1808-
$ref: '#/components/schemas/ConnectionCollectionResponse'
1807+
$ref: '#/components/schemas/ConnectionBulkResponse'
18091808
'401':
1810-
description: Unauthorized
18111809
content:
18121810
application/json:
18131811
schema:
18141812
$ref: '#/components/schemas/HTTPExceptionResponse'
1813+
description: Unauthorized
18151814
'403':
1816-
description: Forbidden
18171815
content:
18181816
application/json:
18191817
schema:
18201818
$ref: '#/components/schemas/HTTPExceptionResponse'
1821-
'409':
1822-
description: Conflict
1819+
description: Forbidden
1820+
'404':
18231821
content:
18241822
application/json:
18251823
schema:
18261824
$ref: '#/components/schemas/HTTPExceptionResponse'
1827-
'201':
1828-
description: Created
1825+
description: Not Found
1826+
'409':
18291827
content:
18301828
application/json:
18311829
schema:
1832-
$ref: '#/components/schemas/ConnectionCollectionResponse'
1830+
$ref: '#/components/schemas/HTTPExceptionResponse'
1831+
description: Conflict
18331832
'422':
18341833
description: Validation Error
18351834
content:
@@ -1850,7 +1849,7 @@ paths:
18501849
as some hook classes tries to find out the `conn` from their __init__ method
18511850
& errors out if not found.
18521851
1853-
It also deletes the conn id env variable after the test.'
1852+
It also deletes the conn id env connection after the test.'
18541853
operationId: test_connection
18551854
requestBody:
18561855
content:
@@ -5983,6 +5982,18 @@ paths:
59835982
schema:
59845983
$ref: '#/components/schemas/HTTPExceptionResponse'
59855984
description: Forbidden
5985+
'404':
5986+
content:
5987+
application/json:
5988+
schema:
5989+
$ref: '#/components/schemas/HTTPExceptionResponse'
5990+
description: Not Found
5991+
'409':
5992+
content:
5993+
application/json:
5994+
schema:
5995+
$ref: '#/components/schemas/HTTPExceptionResponse'
5996+
description: Conflict
59865997
'422':
59875998
description: Validation Error
59885999
content:
@@ -6886,24 +6897,158 @@ components:
68866897
- conn_type
68876898
title: ConnectionBody
68886899
description: Connection Serializer for requests body.
6900+
ConnectionBulkActionResponse:
6901+
properties:
6902+
success:
6903+
items:
6904+
type: string
6905+
type: array
6906+
title: Success
6907+
description: A list of connection_ids representing successful operations.
6908+
errors:
6909+
items:
6910+
type: object
6911+
type: array
6912+
title: Errors
6913+
description: A list of errors encountered during the operation, each containing
6914+
details about the issue.
6915+
type: object
6916+
title: ConnectionBulkActionResponse
6917+
description: 'Serializer for individual bulk action responses.
6918+
6919+
6920+
Represents the outcome of a single bulk operation (create, update, or delete).
6921+
6922+
The response includes a list of successful connection_ids and any errors encountered
6923+
during the operation.
6924+
6925+
This structure helps users understand which key actions succeeded and which
6926+
failed.'
68896927
ConnectionBulkBody:
68906928
properties:
6929+
actions:
6930+
items:
6931+
anyOf:
6932+
- $ref: '#/components/schemas/ConnectionBulkCreateAction'
6933+
- $ref: '#/components/schemas/ConnectionBulkUpdateAction'
6934+
- $ref: '#/components/schemas/ConnectionBulkDeleteAction'
6935+
type: array
6936+
title: Actions
6937+
description: A list of Connection actions to perform.
6938+
type: object
6939+
required:
6940+
- actions
6941+
title: ConnectionBulkBody
6942+
description: Request body for bulk Connection operations (create, update, delete).
6943+
ConnectionBulkCreateAction:
6944+
properties:
6945+
action:
6946+
type: string
6947+
const: create
6948+
title: Action
6949+
default: create
68916950
connections:
68926951
items:
68936952
$ref: '#/components/schemas/ConnectionBody'
68946953
type: array
68956954
title: Connections
6896-
overwrite:
6955+
description: A list of connections to be created.
6956+
action_if_exists:
6957+
type: string
6958+
enum:
6959+
- skip
6960+
- overwrite
6961+
- fail
6962+
title: Action If Exists
6963+
default: fail
6964+
type: object
6965+
required:
6966+
- connections
6967+
title: ConnectionBulkCreateAction
6968+
description: Bulk Create Variable serializer for request bodies.
6969+
ConnectionBulkDeleteAction:
6970+
properties:
6971+
action:
6972+
type: string
6973+
const: delete
6974+
title: Action
6975+
default: delete
6976+
connection_ids:
6977+
items:
6978+
type: string
6979+
type: array
6980+
title: Connection Ids
6981+
description: A list of connection IDs to be deleted.
6982+
action_if_not_exists:
6983+
type: string
6984+
enum:
6985+
- skip
6986+
- fail
6987+
title: Action If Not Exists
6988+
default: fail
6989+
type: object
6990+
required:
6991+
- connection_ids
6992+
title: ConnectionBulkDeleteAction
6993+
description: Bulk Delete Connection serializer for request bodies.
6994+
ConnectionBulkResponse:
6995+
properties:
6996+
create:
68976997
anyOf:
6898-
- type: boolean
6998+
- $ref: '#/components/schemas/ConnectionBulkActionResponse'
68996999
- type: 'null'
6900-
title: Overwrite
6901-
default: false
7000+
description: Details of the bulk create operation, including successful
7001+
connection_ids and errors.
7002+
update:
7003+
anyOf:
7004+
- $ref: '#/components/schemas/ConnectionBulkActionResponse'
7005+
- type: 'null'
7006+
description: Details of the bulk update operation, including successful
7007+
connection_ids and errors.
7008+
delete:
7009+
anyOf:
7010+
- $ref: '#/components/schemas/ConnectionBulkActionResponse'
7011+
- type: 'null'
7012+
description: Details of the bulk delete operation, including successful
7013+
connection_ids and errors.
7014+
type: object
7015+
title: ConnectionBulkResponse
7016+
description: 'Serializer for responses to bulk connection operations.
7017+
7018+
7019+
This represents the results of create, update, and delete actions performed
7020+
on connections in bulk.
7021+
7022+
Each action (if requested) is represented as a field containing details about
7023+
successful connection_ids and any encountered errors.
7024+
7025+
Fields are populated in the response only if the respective action was part
7026+
of the request, else are set None.'
7027+
ConnectionBulkUpdateAction:
7028+
properties:
7029+
action:
7030+
type: string
7031+
const: update
7032+
title: Action
7033+
default: update
7034+
connections:
7035+
items:
7036+
$ref: '#/components/schemas/ConnectionBody'
7037+
type: array
7038+
title: Connections
7039+
description: A list of connections to be updated.
7040+
action_if_not_exists:
7041+
type: string
7042+
enum:
7043+
- skip
7044+
- fail
7045+
title: Action If Not Exists
7046+
default: fail
69027047
type: object
69037048
required:
69047049
- connections
6905-
title: ConnectionBulkBody
6906-
description: Connections Serializer for requests body.
7050+
title: ConnectionBulkUpdateAction
7051+
description: Bulk Update Connection serializer for request bodies.
69077052
ConnectionCollectionResponse:
69087053
properties:
69097054
connections:

0 commit comments

Comments
 (0)