Skip to content

fix: address Copilot review comments from PR #412#413

Merged
chrisdoehring merged 1 commit into
release-20260508from
fix/address-pr412-comments
May 12, 2026
Merged

fix: address Copilot review comments from PR #412#413
chrisdoehring merged 1 commit into
release-20260508from
fix/address-pr412-comments

Conversation

@chrisdoehring
Copy link
Copy Markdown
Contributor

@chrisdoehring chrisdoehring commented May 12, 2026

Summary

Addresses three Copilot review comments on #412 (release-20260508 → main). Merges into release-20260508 so the fixes flow into #412 automatically.

1. Scope id lookup to the integration (was a 500/leak risk)

IntegrationConfiguration.objects.get(id=...) in validate() wasn't scoped to the integration being patched.

  • Nonexistent id → DoesNotExist → unhandled 500.
  • Id belonging to a different integration → accepted, then later repointed by update_or_create's defaults (i.e., one integration could mutate another's config row).

Fix: scope to self.instance.configurations and raise a clean 400 with "Configuration '...' was not found on this integration.".

2. Freeze action on id-updates

update() was passing the full config_data (including any payload action) as defaults to update_or_create. When id was present, that could repoint the row's action — colliding with the (integration, action) UniqueConstraint and bypassing the schema validation in validate() (which keyed off the existing action).

Fix: pop action from defaults when id is present. The portal sometimes echoes action back for client convenience — it's now correctly ignored on id-updates.

3. Tighten test assertions

Replaced assert "..." in str(response.json()) with assert "..." in response.json()["non_field_errors"][0].

Test plan

  • test_patch_integration_config_rejects_unknown_config_id — bogus id → 400 (not 500)
  • test_patch_integration_config_rejects_id_from_different_integration — id from another integration → 400, original config untouched
  • test_patch_integration_config_ignores_action_on_id_update — payload action alongside id is ignored; row's action stays put
  • All 18 integration-config tests pass (pytest -k "config or create_er or create_lotek or test_update_or_create or rejects_* or ignores_*")

Related

🤖 Generated with Claude Code

…action on id-update; tighten test assertions)

Three Copilot review comments on #412:

1. `IntegrationConfiguration.objects.get(id=...)` in validate() wasn't
   scoped to the integration being patched. A nonexistent id surfaced
   as a 500 from DoesNotExist, and an id belonging to a different
   integration was accepted and later repointed via update_or_create's
   defaults. Scope the lookup to `self.instance.configurations` and
   raise a clean 400 with "Configuration '...' was not found on this
   integration."

2. `update()` passed the full `config_data` (including any payload
   `action`) as `defaults` to `update_or_create`. When `id` was present
   that could repoint the row's action — colliding with the
   (integration, action) UniqueConstraint and bypassing the schema
   validation in validate(). Pop `action` from defaults when `id` is
   present so id-updates can only change `data`.

3. Tests asserted on `str(response.json())` — brittle. Assert against
   `response.json()["non_field_errors"][0]` instead.

Added three regression tests:
- unknown config id → 400 (not 500)
- id belonging to a different integration → 400, original config
  untouched
- payload `action` alongside `id` is ignored (action stays put)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses follow-up Copilot review items from PR #412 by tightening nested integration-configuration PATCH behavior: it scopes configuration id lookups to the integration being updated, prevents action from being mutated on id-based updates, and strengthens test assertions to check structured error payloads.

Changes:

  • Scope configuration id validation to self.instance.configurations and return a clean 400 when the id is missing or belongs to a different integration.
  • Ignore payload action when updating configurations by id to prevent action-repointing and (integration, action) uniqueness collisions.
  • Update/add tests to cover unknown ids, cross-integration ids, and “ignore action on id update”, and tighten error assertions to non_field_errors[0].

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
cdip_admin/api/v2/serializers.py Scopes config-id lookup to the integration; ignores action in defaults for id-based updates.
cdip_admin/api/v2/tests/test_integrations_api.py Adds regression tests for scoped id validation and immutable action-on-id-update; tightens error assertions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chrisdoehring chrisdoehring requested review from marianobrc and removed request for marianobrc May 12, 2026 02:47
@chrisdoehring chrisdoehring merged commit d99ecfe into release-20260508 May 12, 2026
5 checks passed
@chrisdoehring chrisdoehring deleted the fix/address-pr412-comments branch May 12, 2026 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants