-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FastAPI API Add test query params standardization an reusability #42320
base: main
Are you sure you want to change the base?
Conversation
return select.order_by(getattr(DagModel, lstriped_orderby).desc()) | ||
else: | ||
return select.order_by(getattr(DagModel, lstriped_orderby).asc()) | ||
return select |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return select |
This will never be hit, the else will.
if self.value: | ||
conditions = [DagModel.tags.any(DagTag.name == tag) for tag in self.value] | ||
return select.where(or_(*conditions)) | ||
|
||
return select |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if self.value: | |
conditions = [DagModel.tags.any(DagTag.name == tag) for tag in self.value] | |
return select.where(or_(*conditions)) | |
return select | |
if self.value is None: | |
return select | |
conditions = [DagModel.tags.any(DagTag.name == tag) for tag in self.value] | |
return select.where(or_(*conditions)) |
Keep it consistent with the others, plus short circuiting out is easier to read imo.
self.value = offset | ||
|
||
return self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.value = offset | |
return self | |
return self.set_value(offset) |
self.value = limit | ||
|
||
return self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.value = limit | |
return self | |
return self.set_value(limit) |
from sqlalchemy.sql import Select | ||
|
||
from airflow.api_fastapi.parameters import BaseParam |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should move these into the if TYPE_CHECKING
block below, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would not ruff
tell you so :-D
from abc import ABC, abstractmethod | ||
from typing import Any, Generic, List, TypeVar, Union | ||
|
||
from fastapi import Depends, HTTPException, Query as Query |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from fastapi import Depends, HTTPException, Query as Query | |
from fastapi import Depends, HTTPException, Query |
items: | ||
type: string | ||
- type: 'null' | ||
type: array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this chane not create the requirement to always pass at least an empty array and does not allow skipping this filter? Is this a breaking change or do I mis-interpret?
else: | ||
return select.order_by(getattr(DagModel, lstriped_orderby).asc()) | ||
return select |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 but then it needs to be:
else: | |
return select.order_by(getattr(DagModel, lstriped_orderby).asc()) | |
return select | |
return select.order_by(getattr(DagModel, lstriped_orderby).asc()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Learning some Python magic every day. That query stuff smells like black magic... but looks cool!
Related to: #42159
This will abstract the handling of common FIlters, Search and Sort query param so we do not have to copy and past the same
query.where(...)
on all endpoints that are using this same logic.This allows:
get_dags
view.order_by
because we were using a sqlalchemytext
clause that do not work with hybrid properties. (cf follow up PR to add ordering bydag_display_name
)The goal is to have that extended and have a library of
query params
that can be re-used accross all the RestAPI.