Repository navigation
UN-4128 [FIX] Stop the pipeline/ETL list page from 500ing #2291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kirtimanmishrazipstack
merged 4 commits into
main
from
UN-4128-pipeline-list-serializer-crash
Sep 18, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7816ea0
UN-4128 [FIX] Stop the Pipeline list page 500ing on the workflow-scop…
kirtimanmishrazipstack d47e4bd
UN-4128 Add regression test for pipeline list serializer crash
kirtimanmishrazipstack 3bf2845
UN-4128 Cover the public many=True constructor in the list-scoping test
kirtimanmishrazipstack 598a08b
Merge branch 'main' into UN-4128-pipeline-list-serializer-crash
kirtimanmishrazipstack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
backend/pipeline_v2/tests/test_pipeline_serializer_list_scoping.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| """``PipelineSerializer.get_fields`` must survive a list request. | ||
|
|
||
| DRF's ``many_init`` builds the child serializer with the same ``instance`` | ||
| argument handed to the list serializer, so a paginated GET binds the page (a | ||
| ``list``) to the child's ``self.instance`` -- never a single ``Pipeline``. | ||
| ``get_fields`` used to guard its workflow-scoping merge with | ||
| ``self.instance is not None``, which is true for that list too, so it called | ||
| ``.workflow_id`` on a ``list`` and crashed every pipeline/ETL list request | ||
| with an ``AttributeError``. The guard now checks ``isinstance(self.instance, | ||
| Pipeline)`` instead. | ||
|
|
||
| The real module is imported and its collaborator patched (Django is loaded by | ||
| the rig's test env), so no database is touched and this stays in the unit | ||
| tier. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import uuid | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| from pipeline_v2.models import Pipeline | ||
| from pipeline_v2.serializers.crud import PipelineSerializer | ||
| from workflow_manager.workflow_v2.models.workflow import Workflow | ||
|
|
||
| MUTABLE_WORKFLOWS_PATH = "pipeline_v2.serializers.crud.mutable_workflows_for" | ||
|
|
||
|
|
||
| class TestWorkflowFieldScopingSurvivesAList: | ||
| """The instance-type guard in ``get_fields`` must not crash on a list.""" | ||
|
|
||
| def test_list_instance_does_not_crash(self) -> None: | ||
| """A paginated list's ``self.instance`` is a ``list``, not a ``Pipeline``.""" | ||
| serializer = PipelineSerializer() | ||
| serializer.instance = [MagicMock(spec=Pipeline)] | ||
|
|
||
| with patch(MUTABLE_WORKFLOWS_PATH, return_value=Workflow.objects.none()): | ||
| fields = serializer.get_fields() # must not raise AttributeError | ||
|
|
||
| assert "workflow" in fields | ||
|
|
||
| def test_many_true_construction_does_not_crash(self) -> None: | ||
| """The public ``PipelineSerializer(queryset, many=True)`` entry point.""" | ||
| with patch(MUTABLE_WORKFLOWS_PATH, return_value=Workflow.objects.none()): | ||
| serializer = PipelineSerializer([MagicMock(spec=Pipeline)], many=True) | ||
| fields = serializer.child.fields # must not raise AttributeError | ||
|
|
||
| assert "workflow" in fields | ||
|
|
||
| def test_single_instance_still_scopes_to_its_own_workflow(self) -> None: | ||
| """A detail/update request keeps the co-owner carve-out for its own workflow.""" | ||
| pipeline = MagicMock(spec=Pipeline, workflow_id=uuid.uuid4()) | ||
| serializer = PipelineSerializer() | ||
| serializer.instance = pipeline | ||
|
|
||
| with patch(MUTABLE_WORKFLOWS_PATH, return_value=Workflow.objects.none()): | ||
| with patch.object( | ||
| Workflow.objects, "filter", wraps=Workflow.objects.filter | ||
| ) as mocked_filter: | ||
| serializer.get_fields() | ||
|
|
||
| mocked_filter.assert_called_once_with(pk=pipeline.workflow_id) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.