bugraoz93 commented on code in PR #42782:
URL: https://github.com/apache/airflow/pull/42782#discussion_r1794301943


##########
airflow/api_fastapi/parameters.py:
##########
@@ -181,11 +193,53 @@ def to_orm(self, select: Select) -> Select:
         select = select.order_by(None)
 
         if self.value[0] == "-":
-            return select.order_by(nullscheck, column.desc(), 
DagModel.dag_id.desc())
+            return select.order_by(nullscheck, column.desc(), 
self.order_column.desc())
         else:
-            return select.order_by(nullscheck, column.asc(), 
DagModel.dag_id.asc())
+            return select.order_by(nullscheck, column.asc(), 
self.order_column.asc())
+
+    def depends(self, order_by: str) -> SortParam:
+        return self.set_value(order_by)
+
+
+class SortConnectionParam(SortParam):
+    """Order Connection by the attribute."""
 
-    def depends(self, order_by: str = "dag_id") -> SortParam:
+    def __init__(self, allowed_attrs: list[str]) -> None:
+        super().__init__(
+            allowed_attrs=allowed_attrs,
+            attr_mapping={
+                "connection_id": Connection.conn_id,
+                "conn_type": Connection.conn_type,
+                "description": Connection.description,
+                "host": Connection.host,
+                "port": Connection.port,
+                "id": Connection.id,
+            },
+            model=Connection,
+            order_column=Connection.conn_id,
+            to_replace={"connection_id": "conn_id"},
+        )
+

Review Comment:
   I changed it according to your suggestions. I think this is indeed better 
since we don't need to define any subclasses for each model we have. :)



-- 
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]

Reply via email to