blag commented on code in PR #26358:
URL: https://github.com/apache/airflow/pull/26358#discussion_r973332330


##########
airflow/www/views.py:
##########
@@ -3547,6 +3553,109 @@ def dataset_dependencies(self):
             {'Content-Type': 'application/json; charset=utf-8'},
         )
 
+    # @format_parameters({'limit': check_limit})
+    @expose('/object/list_datasets')
+    @auth.has_access([(permissions.ACTION_CAN_READ, 
permissions.RESOURCE_DATASET)])
+    def get_datasets(self):
+        """Get datasets"""
+        allowed_attrs = ['uri', 'last_dataset_update']
+
+        limit = int(request.args.get("limit", 25))
+        offset = int(request.args.get("offset", 0))
+        order_by = request.args.get("order_by", "uri")
+        lstripped_orderby = order_by.lstrip('-')
+
+        if lstripped_orderby not in allowed_attrs:
+            return {
+                "detail": (
+                    f"Ordering with '{lstripped_orderby}' is disallowed or the 
attribute does not "
+                    "exist on the model"
+                )
+            }, 400
+
+        limit = 50 if limit > 50 else limit
+
+        with create_session() as session:
+            if lstripped_orderby == "uri":
+                if order_by[0] == "-":
+                    order_by = (DatasetModel.uri.desc(),)
+                else:
+                    order_by = (DatasetModel.uri.asc(),)
+            elif lstripped_orderby == "last_dataset_update":

Review Comment:
   It's absolutely disappointingly messy, that's for sure. 😕
   
   I do think that supporting both asc/desc is useful for answering different 
questions, but I'm not 100% sure if the nulls first/last for the respective 
ordering is the most optimal, especially for deployments with a great many 
datasets. Totally willing to nix and fix the pairings if we don't like that.



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