Repository navigation
Fix trigger API scalability for large DAG authorization sets - #76965
adiranjan25 wants to merge 4 commits into
Conversation
| @@ -365,6 +365,29 @@ def test_filters(self, test_client, triggers, params, expected): | |||
| assert response.status_code == 200 | |||
| assert sorted(_name(t) for t in response.json()["triggers"]) == expected | |||
|
|
|||
| def test_pagination_counts_multi_watcher_trigger_once(self, test_client, session, triggers): | |||
There was a problem hiding this comment.
Could you add a test that mocks get_authorized_dag_ids so some triggers are hidden, then walks the pages with limit/offset and asserts total_entries and the order?
There was a problem hiding this comment.
Thanks, @henry3260 . Added test_pagination_excludes_unauthorized_triggers, which mocks get_authorized_dag_ids, verifies hidden triggers are excluded, walks the results using limit/offset, and checks ordering and total_entries. The updated trigger API test suite passes locally (57 tests).
| if owner_ref.get("callback_id") is not None: | ||
| return dag_id in self.callback_dag_ids | ||
| return bool(watched_asset_ids & self.asset_ids) | ||
|
|
||
| def to_orm(self, select: Select) -> Select: |
There was a problem hiding this comment.
Could we remove PermittedTriggerFilter.to_orm() and _select_triggers_watching()? This PR replaces to_orm() with allows(), so neither has a caller left, and keeping both means the same permission rule lives in two places.
There was a problem hiding this comment.
Thanks, @henry3260 . Removed PermittedTriggerFilter.to_orm() and _select_triggers_watching(), along with the unused imports. I also removed the OrmClause inheritance because to_orm() was its required abstract method. The existing allows() implementation remains unchanged. Ruff checks and all 57 trigger API tests pass locally.
|
Hi @henry3260, thanks again for the review. I've pushed commit All 57 trigger API tests and Ruff checks passed locally. CI workflow approval is currently pending. Could you please take another look when convenient? Thanks! |
There was a problem hiding this comment.
Thanks for taking this on! Looking good, few things: Needs a rebase now that #76567 is in: owner_ref is now used_by_ref, and owner_still_refers_expression is now still_used_expression.
| current_owner_ref = None | ||
| current_assets = set() | ||
|
|
||
| def include_candidate(): |
There was a problem hiding this comment.
Rows of one trigger come back next to each other, because the sort always ends with the id, so itertools.groupby(candidate_rows, key=itemgetter(0)) could replace include_candidate and the current_* state.
| assert paged_ids == expected_ids | ||
|
|
||
| @mock.patch(f"{BASE_AUTH}.get_authorized_dag_ids", autospec=True) | ||
| def test_pagination_excludes_unauthorized_triggers(self, mock_dag_ids, test_client, session, triggers): |
There was a problem hiding this comment.
This hides only task triggers. A callback and a watcher the caller can't read in the same walk would page all three branches of allows.
| ), | ||
| ) | ||
| ) | ||
| def allows(self, *, dag_id: str | None, owner_ref: dict | None, watched_asset_ids: set[int]) -> bool: |
There was a problem hiding this comment.
#76560 adds the same check on a loaded trigger as PermittedTriggerFilter.permits(trigger), so whichever of the two lands second should use the other's.
bb11e8b to
5310697
Compare
|
Hi @seanghaeli, thank you for the detailed review and suggestions. I've rebased PR #76965 onto the latest upstream main and force-pushed the updated implementation ( Changes completed:
Validation: All 71 trigger API tests pass locally. Ruff lint, formatting, and whitespace checks also pass. I've also noted the overlapping authorization logic in #76560 and will coordinate reuse depending on which PR merges first. The new mixed-authorization test covers visible and hidden triggers, though I can further extend it to explicitly hide all three trigger categories if needed. CI workflow approval is currently pending. Would appreciate another review when convenient. Thank you! |
|
Thanks @seanghaeli for the review. I've further strengthened the pagination regression tests with three authorization scenarios, including hidden task, callback, and asset-watcher triggers. Validation:
The updated tests verify authorization-aware pagination, ordering, offsets, and Would appreciate another review when convenient. Thanks! |
|
Hi @seanghaeli, I noticed that the Tests (AMD) and CodeQL workflows for the latest commit ( The implementation has been updated to address the previous review feedback, including the strengthened authorization-aware pagination tests. Local validation:
Could you please approve the CI workflows when convenient? If the existing workflow runs have expired, I would appreciate your guidance on triggering fresh runs. I'm happy to address any additional review feedback or actionable CI failures. Thank you again for your time and guidance! |
Fixes #76959
Avoid expanding large authorized DAG and asset sets into SQL IN clauses when listing or retrieving triggers.
Authorization is evaluated using trigger ownership and watcher information, while preserving SQL filtering, deterministic ordering, exact counts, and pagination.
Validation: