jscheffl commented on code in PR #48109:
URL: https://github.com/apache/airflow/pull/48109#discussion_r2010854162


##########
airflow-core/src/airflow/api_fastapi/core_api/services/public/connections.py:
##########
@@ -34,6 +34,29 @@
 from airflow.models.connection import Connection
 
 
+def update_orm_from_pydantic(
+    orm_conn: Connection, pydantic_conn: ConnectionBody, update_mask: 
list[str] | None = None
+):
+    """Update ORM object from Pydantic object."""
+    # Not all fields match and some need setters, therefore copy manually
+    if not update_mask or "conn_type" in update_mask:
+        orm_conn.conn_type = pydantic_conn.conn_type
+    if not update_mask or "description" in update_mask:
+        orm_conn.description = pydantic_conn.description
+    if not update_mask or "host" in update_mask:
+        orm_conn.host = pydantic_conn.host
+    if not update_mask or "schema" in update_mask:
+        orm_conn.schema = pydantic_conn.schema_
+    if not update_mask or "login" in update_mask:
+        orm_conn.login = pydantic_conn.login
+    if not update_mask or "password" in update_mask:
+        orm_conn.set_password(pydantic_conn.password)
+    if not update_mask or "port" in update_mask:
+        orm_conn.port = pydantic_conn.port
+    if not update_mask or "extra" in update_mask:
+        orm_conn.set_extra(pydantic_conn.extra)

Review Comment:
   If you and @ash "insist" on making it generic I could make a generic field 
setter. With the exception of conn ID and add some exceptions and manual 
tweaking for the setters, whereas the update mask  need to be considered as 
well. so I don't know if this is better readable or better maintainable. I just 
would like to make it usable before RC1.



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to