Commit 35e4c7f
committed
fix(run-storage): validate cursor order_by column
## Summary & Motivation
Cursor pagination is invalid when the `order_by` doesn't match
the `cursor` and/or the cursor doesn't completely cover the
index. Validate that this doesn't happen, and raise if it ever
does happen.
`_add_cursor_limit_to_query` in `SqlRunStorage` previously
allowed semantically invalid cursor pagination with a non-`id`
`order_by` column. This would silently apply `id`-based cursor
filtering while sorting by the requested column — producing
incorrect, page-skipping results with no error.
This change adds explicit guards:
- If `cursor` is provided and `order_by` maps to a **non-unique
column** (e.g. `status`), a `ParameterCheckError` is raised
immediately, since cursor pagination on a non-unique column is
undefined.
- If `cursor` is provided and `order_by` maps to a **unique non-`id`
column** (e.g. `run_id`), a `NotImplementedCheckError` is raised,
since stable single-column cursor pagination over an arbitrary unique
key is not yet implemented.
- The existing `id`-based cursor path is unchanged.
## How I Tested These Changes
Two new test cases in `TestRunStorage` cover both error branches:
`test_cursor_pagination_with_non_unique_order_by_raises` and
`test_cursor_pagination_with_unique_non_id_order_by_raises`.
## Changelog
`DagsterInstance.get_run_records`, `RunStorage.get_runs`, and
`RunStorage.get_run_records`: passing `cursor` together with an
`order_by` column other than `id` now raises an explicit error
instead of silently returning wrong results.1 parent b8b7f3f commit 35e4c7f
2 files changed
Lines changed: 47 additions & 6 deletions
File tree
- python_modules/dagster
- dagster_tests/storage_tests/utils
- dagster/_core/storage/runs
Lines changed: 28 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
280 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
281 | 286 | | |
282 | | - | |
283 | | - | |
284 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
285 | 304 | | |
286 | | - | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
287 | 310 | | |
288 | 311 | | |
289 | 312 | | |
290 | 313 | | |
291 | | - | |
292 | 314 | | |
293 | 315 | | |
294 | 316 | | |
| |||
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
940 | 941 | | |
941 | 942 | | |
942 | 943 | | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
943 | 962 | | |
944 | 963 | | |
945 | 964 | | |
| |||
0 commit comments