feat(ml): filter algorithm list by project pipelines#1249
Conversation
Scope AlgorithmViewSet.list() by the active project: only return algorithms belonging to pipelines that have an enabled ProjectPipelineConfig for the requested project_id. Mirrors the existing PipelineViewSet filtering pattern so the /ml/algorithms/ list in the UI matches /ml/pipelines/ and /ml/processing_services/. Unscoped requests (no project_id) are unchanged — they still list all algorithms — so admin/debug usage and existing AlgorithmCategoryMap endpoints that cross-reference algorithms keep working. Detail (/ml/algorithms/<id>/) is also unchanged, so clicking an algorithm reference from a classification in a project where the pipeline is now disabled continues to resolve. Co-Authored-By: Claude <noreply@anthropic.com>
✅ Deploy Preview for antenna-preview canceled.
|
✅ Deploy Preview for antenna-ssec canceled.
|
📝 WalkthroughWalkthroughAdds project-based filtering to the algorithms endpoint. The Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Pull request overview
Scopes the ML algorithms list endpoint to the active project so the algorithms page aligns with existing project-scoped ML pipeline and processing-service endpoints.
Changes:
- Update
AlgorithmViewSet.get_queryset()to filter algorithms to those in pipelines with an enabledProjectPipelineConfigfor the requestedproject_id. - Add OpenAPI schema annotation for
project_idon the algorithmslist()endpoint. - Add API tests to verify enabled-only scoping by project and unchanged unscoped behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
ami/ml/views.py |
Applies project-based filtering for algorithm listings and documents project_id on the list endpoint. |
ami/ml/tests.py |
Adds test coverage for project-scoped algorithm listing behavior (enabled-only, per-project isolation, unscoped unchanged). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@ami/ml/views.py`:
- Around line 59-64: The project-scoped filter in AlgorithmViewSet.get_queryset
unconditionally narrows results causing detail/retrieve endpoints to 404; modify
get_queryset to only apply the pipelines__project_pipeline_configs__project and
enabled=True filter when self.action == 'list' (i.e., keep detail/retrieve
unscoped). Locate the get_queryset method and wrap or gate the existing qs =
qs.filter(...) block so it only runs for the 'list' action, leaving other
actions (retrieve) to return the unfiltered queryset.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 36183fdf-864a-4e96-8060-1b5736dec613
📒 Files selected for processing (2)
ami/ml/tests.pyami/ml/views.py
…_with_params Addresses review feedback on #1249: - AlgorithmViewSet.get_queryset now applies the project-pipeline filter only when self.action == "list". Detail (retrieve) stays unscoped so /ml/algorithms/<id>/?project_id=<p> still resolves for historical classification links whose pipeline is no longer enabled. - Test helper now builds URLs via reverse_with_params("api:algorithm-list") to match the pattern used elsewhere in ami/ml/tests.py. - New test confirms the detail endpoint returns the algorithm even when project_id refers to a project whose pipeline is disabled for it. Co-Authored-By: Claude <noreply@anthropic.com>


Summary
Scope the
/api/v2/ml/algorithms/?project_id=<id>list to algorithms that belong to pipelines with an enabledProjectPipelineConfigfor that project. Previously the endpoint returned everyAlgorithmin the database regardless ofproject_id, whileml/pipelines/andml/processing_services/already filtered by project. This aligns the algorithms page at/projects/<id>/algorithmswith the pipelines and processing services pages.ami/ml/views.py:AlgorithmViewSet.get_queryset()filters bypipelines__project_pipeline_configs__project=<project>, enabled=Truewhen aproject_idis supplied. No filter when omitted, so admin/debug views and theAlgorithmCategoryMapcross-reference keep working.AlgorithmViewSet.list()gets theproject_id_doc_paramschema annotation for parity with the pipeline/processing-service endpoints./ml/algorithms/<id>/) is intentionally left unscoped — clicking an algorithm reference from a classification in a project whose pipeline is no longer enabled still resolves.ami/ml/tests.py: addsTestAlgorithmViewSetProjectFiltercovering the enabled-only scoping, isolation between projects, and unchanged behavior whenproject_idis omitted.Scope kept deliberately narrow
The user flagged that algorithms can also be referenced from historical classifications on a project whose pipeline has since been disabled. I kept this first pass simple: the list is scoped to currently enabled pipelines only, and the detail endpoint stays unscoped so those historical classification links don't 404.
Follow-up options (not in this PR)
In order of increasing effort / risk, if we want the list to also reflect historical usage:
enabled=Trueso the list shows every pipeline that has anyProjectPipelineConfigfor the project, enabled or not. One-line change. Matches the UX where a disabled pipeline's algorithm still appears because the project has touched it.filter(Q(pipelines__project_pipeline_configs__project=<p>, enabled=True) | Q(classifications__detection__occurrence__project=<p>)).distinct(). Lets the list surface algorithms that processed data in the project even if the pipeline was never formally configured. The classifications → detection → occurrence join is the expensive piece; worth benchmarking on a project with many occurrences before shipping.publicflag) as globally visible; otherwise gate detail on membership in at least one project whose configs include the pipeline. More invasive — needs a policy decision on what 'generally available' means for a pipeline.Happy to follow up with option 1 or 2 once the team picks a direction.
Test plan
docker compose -f docker-compose.ci.yml run --rm django python manage.py test ami.ml.tests.TestAlgorithmViewSetProjectFilter --keepdbTestProjectPipelinesAPIstill passes (no regression in neighboring project-scoping logic)/projects/<id>/algorithmson the local stack for a project with both enabled and disabled pipelines; confirm only enabled-pipeline algorithms appearSummary by CodeRabbit
project_idquery parameter, returning only algorithms from pipelines enabled for that specific project.