feat: Create Pydantic models for Search Pipeline Run API#106
feat: Create Pydantic models for Search Pipeline Run API#106yuechao-qin wants to merge 1 commit intoycq/search-pipeline-run-query-paramsfrom
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Volv-G
left a comment
There was a problem hiding this comment.
looks good, just 1 question on the design choice
78fdccf to
f7dc9bc
Compare
962d30e to
44babd7
Compare
f7dc9bc to
b5f0ba9
Compare
44babd7 to
e853104
Compare
e853104 to
f0a5c13
Compare
b5f0ba9 to
88b265f
Compare
88b265f to
9a0930e
Compare
f0a5c13 to
b57b335
Compare
|
|
||
| class ValueEquals(_BaseModel): | ||
| key: NonEmptyStr | ||
| value: NonEmptyStr |
There was a problem hiding this comment.
Hmm. Maybe empty value is OK.
| ambiguous timestamps that could silently resolve to the wrong timezone.""" | ||
|
|
||
| key: NonEmptyStr | ||
| start_time: pydantic.AwareDatetime |
There was a problem hiding this comment.
start_time can be optional too
|
|
||
| class TestFilterQuery: | ||
| def test_full_example_from_design_doc(self): | ||
| json_str = """ |
There was a problem hiding this comment.
if you want, you can construct Python dict and then use json.dumps to serialize it.
But JSON string like you have is OK too.
| pass | ||
|
|
||
|
|
||
| class MutuallyExclusiveFilterError(ApiValidationError): |
There was a problem hiding this comment.
MutuallyExclusiveFilterError is pretty specific to pipeline run search. Maybe it should be declared in that module? Or you can just use ApiValidationError
Or if you envision more APIs with mutually exclusive parameters (we avoid this), you could rename the class to MutuallyExclusiveParametersError.

TL;DR
Added a new
filter_queryparameter to the pipeline runs API with Pydantic validation models, while maintaining backward compatibility with the existingfilterparameter.What's new?
JSON definition for
filter_query:{ // logical (any predicate) "<and|or>": [ // leaf {"key_exists": {"key": "<KEY>"}}, // leaf {"value_contains": {"key": "<KEY>", "value_substring": "<VALUE>"}}, // leaf {"value_in": {"key": "<KEY>", "values": ["<V1>", "<V2>", "..."]}}, // leaf {"value_equals": {"key": "<KEY>", "value": "<VALUE>"}}, // leaf {"time_range": {"key": "system/pipeline_run.date.created_at", "start_time": "<START_DATE>", "end_time": "<END_DATE>"}}, // logical (leaf only) {"not": {"<LEAF_PREDICATE>": {}}}, // logical (any predicate) {"<and|or>": [...]}, ... ] }Example JSON for
filter_query:{ "and": [ {"key_exists": {"key": "team"}}, {"value_equals": {"key": "env", "value": "prod"}}, {"value_in": {"key": "region", "values": ["us-east", "us-west", "eu-west"]}}, {"not": {"key_exists": {"key": "deprecated"}}}, {"or": [{"value_contains": {"key": "name", "value_substring": "nightly"}}]} ] }What changed?
API
GET /api/pipeline_runs/Functional
filter_queryif used in API will return an HTTP 501 (unimplemented error)filterorfilter_query(mutual exclusive) can be in the API, else it returns a HTTP 422.Other
filter_queryparameter toListPipelineRunsParamsthat accepts structured JSON queriesfilter_query_models.pyfor validating filter queries, including:key_exists,value_equals,value_contains,value_in,time_rangeand,or,notfilter_querywith proper error handlingHow to test?
filter_queryparameter with valid JSON structures like{"and": [{"key_exists": {"key": "team"}}]}filterandfilter_querysimultaneously returns a 422 errorfilter_querytriggers proper validation errorsfilter_queryusage returns a 501 "not yet implemented" responseWhy make this change?
This PR introduces the Pydantic models and API wiring that upstream PRs depend on to implement the Search Pipeline Run API.