Skip to content

fix: skip organization PATCH when no top-level properties have changed - #1461

Open
ankita10119 wants to merge 2 commits into
masterfrom
DXCDT-2214
Open

fix: skip organization PATCH when no top-level properties have changed#1461
ankita10119 wants to merge 2 commits into
masterfrom
DXCDT-2214

Conversation

@ankita10119

Copy link
Copy Markdown
Contributor

🔧 Changes

The deploy CLI was issuing a PATCH /api/v2/organizations/{id} for every organization on every import run, regardless of whether anything had changed. On tenants with many organizations this caused unnecessary API load and rate limit errors.

Root cause: calculateChanges categorises any org present in both the local config and the remote tenant as an update by identifier match alone, no field comparison is performed. updateOrganization then unconditionally called organizations.update() for every org in that bucket.

Fix: Before calling organizations.update(), the desired top-level fields are now compared against the remote state using deep equality (isEqual + pick). The PATCH is only issued when a field has actually changed. A changed flag tracks whether any API call was made (main PATCH or any sub-resource mutation); didUpdate and the updated counter are gated on that flag so the CLI output only reflects real changes.

Sub-resource diffing (connections, client grants, discovery domains, org-client associations) is unaffected — those paths already only make API calls when changes are detected.

📚 References

  • Fixes: deploy CLI updating all orgs on every import regardless of changes

🔬 Testing

Unit tests (test/tools/auth0/handlers/organizations.tests.js - #organizations skip-unchanged updates):

  • No-op import → organizations.update not called, handler.updated === 0
  • Changed display_name → PATCH fires for that org only, counter increments
  • Changed nested branding object → deep equality catches it, PATCH fires
  • Identical branding → PATCH skipped
  • 2 orgs, 1 changed → only the changed org is PATCHed, counter is 1
  • Connection-only change → org PATCH skipped, connection update fires
  • Fully identical org + all connections → zero API calls end-to-end

Manual (31-org tenant):

  • Export all orgs → re-import unchanged → 0 PATCHes (previously 31)
  • Export → change display_name on one org → import → 1 PATCH for that org only

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

@ankita10119
ankita10119 requested a review from a team as a code owner August 13, 2026 08:27
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.30435% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.46%. Comparing base (88e3e61) to head (99edc55).

Files with missing lines Patch % Lines
src/tools/auth0/handlers/organizations.ts 91.30% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1461      +/-   ##
==========================================
+ Coverage   80.43%   80.46%   +0.03%     
==========================================
  Files         163      163              
  Lines        7712     7729      +17     
  Branches     1708     1716       +8     
==========================================
+ Hits         6203     6219      +16     
  Misses        810      810              
- Partials      699      700       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

3 participants