pierrejeambrun commented on code in PR #48109: URL: https://github.com/apache/airflow/pull/48109#discussion_r2010001285
########## 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: I would have to take a deeper look but I agree with Ash. We normally don't use that because the powerful aliasing system of pydantic should be enough. We had plenty of cases like this on other datamodel and we could always find a way. (maybe not this time but I'm convinced we can). Validation alias vs serializer alias, alias generator etc... ########## 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: This is for going from request to PydanticModel. For going from PydanticModel <=> ORMInstance indeed setters are a problem and we need to do that manually. (or via a service function) (from_datamodel_to_orm basically) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
