|
34 | 34 | from airflow.models.connection import Connection
|
35 | 35 |
|
36 | 36 |
|
| 37 | +def update_orm_from_pydantic( |
| 38 | + orm_conn: Connection, pydantic_conn: ConnectionBody, update_mask: list[str] | None = None |
| 39 | +): |
| 40 | + """Update ORM object from Pydantic object.""" |
| 41 | + # Not all fields match and some need setters, therefore copy manually |
| 42 | + if not update_mask or "conn_type" in update_mask: |
| 43 | + orm_conn.conn_type = pydantic_conn.conn_type |
| 44 | + if not update_mask or "description" in update_mask: |
| 45 | + orm_conn.description = pydantic_conn.description |
| 46 | + if not update_mask or "host" in update_mask: |
| 47 | + orm_conn.host = pydantic_conn.host |
| 48 | + if not update_mask or "schema" in update_mask: |
| 49 | + orm_conn.schema = pydantic_conn.schema_ |
| 50 | + if not update_mask or "login" in update_mask: |
| 51 | + orm_conn.login = pydantic_conn.login |
| 52 | + if not update_mask or "password" in update_mask: |
| 53 | + orm_conn.set_password(pydantic_conn.password) |
| 54 | + if not update_mask or "port" in update_mask: |
| 55 | + orm_conn.port = pydantic_conn.port |
| 56 | + if not update_mask or "extra" in update_mask: |
| 57 | + orm_conn.set_extra(pydantic_conn.extra) |
| 58 | + |
| 59 | + |
37 | 60 | class BulkConnectionService(BulkService[ConnectionBody]):
|
38 | 61 | """Service for handling bulk operations on connections."""
|
39 | 62 |
|
@@ -118,14 +141,7 @@ def handle_bulk_update(
|
118 | 141 | ConnectionBody(**connection.model_dump())
|
119 | 142 |
|
120 | 143 | # Not all fields match and some need setters, therefore copy manually
|
121 |
| - old_connection.conn_type = connection.conn_type |
122 |
| - old_connection.description = connection.description |
123 |
| - old_connection.host = connection.host |
124 |
| - old_connection.schema = connection.schema_ |
125 |
| - old_connection.login = connection.login |
126 |
| - old_connection.set_password(connection.password) |
127 |
| - old_connection.port = connection.port |
128 |
| - old_connection.set_extra(connection.extra) |
| 144 | + update_orm_from_pydantic(old_connection, connection) |
129 | 145 | results.success.append(connection.connection_id)
|
130 | 146 |
|
131 | 147 | except HTTPException as e:
|
|
0 commit comments