Skip to content

[chores:fix] Fixed PKI API query count regression due to DRF 3.18 - #1503

Merged
nemesifier merged 1 commit into
masterfrom
fix-ci
Oct 8, 2026
Merged

nemesifier merged 1 commit into
masterfrom
fix-ci

Conversation

@dee077

@dee077 dee077 commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Checklist

Description of Changes

Two tests are currently failin in CI with an increased query count:

  1. test_ca_put_api — 8 instead of 6
  2. test_cert_put_api — 11 instead of 10

See: https://github.com/openwisp/openwisp-controller/actions/runs/37550871419/job/112565767578.

Reason

We have set the common_name field in the Ca and Cert models with a unique constraint on ("common_name", "organization"), so the uniqueness is already checked by the model and enforced by the database.

With the latest DRF 3.18 update in openwisp-utils, common_name is picked up by the serializer's UniqueTogetherValidator for ("common_name", "organization"), so it checks this uniqueness again. Every PUT now re-checks it at the serializer level on top of the model's own UniqueConstraint check, which costs 2 extra queries per request:

  • one to fetch the related organization
  • one SELECT to probe for an existing (common_name, organization) row

Introduced in DRF 3.18.2.

Solution

  1. Declare common_name explicitly as a read-only field in
    CaDetailSerializer and CertDetailSerializer. It is not editable after
    creation anyway, and the value is already validated by the model, so the
    duplicate check and its 2 queries are avoided.

  2. Alternatively, if we would rather not add a read-only field, we can simply
    bump the expected query counts in the two tests (6 → 8 and 10 → 11) and
    accept the 2 extra queries per request.

Let me know if the second one is better; I have gone ahead with the first.

How to verify

Make sure the virtualenv has DRF = 3.18.3 then remove the two common_name lines from openwisp_controller/pki/api/serializers.py and run tests

Both tests fail with the counts above; with the fix in place, the suite passes.

@dee077 dee077 self-assigned this Oct 8, 2026
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: a612c35e-a992-4756-a1c6-d689bece0d57
📥 Commits

Reviewing files that changed from the base of the PR and between 91d3885 and 1b951ea.

📒 Files selected for processing (1)
  • openwisp_controller/pki/api/serializers.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (10)
  • GitHub Check: auto-assign-issue / run-bot
  • GitHub Check: Python==3.12 | django~=5.2.0
  • GitHub Check: Python==3.10 | django~=5.1.0
  • GitHub Check: Python==3.11 | django~=5.2.0
  • GitHub Check: Python==3.13 | django~=5.1.0
  • GitHub Check: Python==3.10 | django~=5.2.0
  • GitHub Check: Python==3.12 | django~=5.1.0
  • GitHub Check: Python==3.13 | django~=5.2.0
  • GitHub Check: Python==3.11 | django~=5.1.0
  • GitHub Check: Analyze (python)
🧰 Additional context used
📓 Path-based instructions (1)
Flag potential security vulnerabilities Flag obvious performance regressions, such as heavy loops, repeated I/O, or unoptimized queries Flag unused or redundant code Flag outdated or incorrect comments/docstrings Ensure new code handles err...

⚙️ CodeRabbit configuration file

Files:

  • openwisp_controller/pki/api/serializers.py
🔇 Additional comments (2)
openwisp_controller/pki/api/serializers.py (2)

101-101: LGTM!


185-185: LGTM!


📝 Walkthrough

Walkthrough

CaDetailSerializer and CertDetailSerializer now explicitly declare common_name as read-only.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 1b951

The CA and certificate detail API contracts are preserved; no actionable merge risk is evident.


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Title check ❌ Error The title accurately describes the PKI API query-count regression and its fix, but the prefix is invalid. The requirements allow one prefix such as [fix] or [chores], while the title uses the combined… Replace [chores:fix] with a single approved prefix, preferably [fix], such as "[fix] Fixed PKI API query count regression due to DRF 3.18".
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Ui Changes, Regression Test, Docs ✅ Passed The PR changes only two serializer declarations. It does not change an end-user UI, add a feature, or change documented behavior, so screenshots and documentation updates are not required. Existing PK…
Description check ✅ Passed The description explains the regression, root cause, solution, affected tests, and verification steps. It does not include the required Reference to Existing Issue section or Screenshot section, and t…
Full details: Title check

Explanation

The title accurately describes the PKI API query-count regression and its fix, but the prefix is invalid. The requirements allow one prefix such as [fix] or [chores], while the title uses the combined prefix [chores:fix].

  • Fix all pre-merge checks with AI
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@openwisp-companion

Copy link
Copy Markdown

Proposed change log entry:

[fix] Fixed PKI API query count regression in CI #1503

Declared common_name explicitly as a read-only field in
CaDetailSerializer and CertDetailSerializer to prevent duplicate
uniqueness checks introduced by recent Django REST Framework updates.
This avoids the extra database queries during PUT requests and resolves
the CI query count failures.

Closes #1503

@nemesifier nemesifier changed the title [fix] Fixed PKI API query count regression in CI [chores:fix] Fixed PKI API query count regression in CI Oct 8, 2026
@nemesifier nemesifier changed the title [chores:fix] Fixed PKI API query count regression in CI [chores:fix] Fixed PKI API query count regression due to DRF 3.18 Oct 8, 2026
@nemesifier
nemesifier merged commit 80f64dd into master Oct 8, 2026
27 of 29 checks passed
@nemesifier
nemesifier deleted the fix-ci branch October 8, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants