Skip to content

Commit b06de62

Browse files
committed
refactor(admin): replace dynamic subquery with explicit join (#772)
The `reana-admin retention-rules-apply` command selected candidate retention rules either from `workflow.retention_rules` (a query object, under the old `lazy="dynamic"` setting on `Workflow.retention_rules`) or by joining onto `user.workflows.subquery()` (a subquery built from the dynamic `User.workflows` query). After dropping `lazy="dynamic"` in reana-db so these relationships return regular lists, the previous code no longer works: lists have neither a `.subquery()` method nor the follow-up `.filter(...)` chain that the rest of the function relies on. Replace both branches with explicit queries on `WorkspaceRetentionRule`: filter by `workflow_id` for the single-workflow case, and join `Workflow` filtered by `owner_id` for the per-user case. Result is the same set of rows, but expressed through standard `Session.query(...)` calls.
1 parent 429f279 commit b06de62

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

  • reana_server/reana_admin

reana_server/reana_admin/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,10 +764,10 @@ def retention_rules_apply(
764764

765765
candidate_rules = Session.query(WorkspaceRetentionRule)
766766
if workflow:
767-
candidate_rules = workflow.retention_rules
767+
candidate_rules = candidate_rules.filter_by(workflow_id=workflow.id_)
768768
elif user:
769-
candidate_rules = Session.query(WorkspaceRetentionRule).join(
770-
user.workflows.subquery()
769+
candidate_rules = candidate_rules.join(Workflow).filter(
770+
Workflow.owner_id == user.id_
771771
)
772772

773773
click.echo("Setting the status of all the rules that will be applied to `pending`")

0 commit comments

Comments
 (0)