Skip to content

Defer cloud SDK imports across AWS RDS, Azure, and Google Cloud - #10362

Open
dev-hari-prasad wants to merge 1 commit into
pgadmin-org:masterfrom
dev-hari-prasad:defer-cloud-sdk-imports
Open

Defer cloud SDK imports across AWS RDS, Azure, and Google Cloud#10362
dev-hari-prasad wants to merge 1 commit into
pgadmin-org:masterfrom
dev-hari-prasad:defer-cloud-sdk-imports

Conversation

@dev-hari-prasad

@dev-hari-prasad dev-hari-prasad commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Moves heavy cloud SDK imports (boto3, azure.*, googleapiclient, google_auth_oauthlib) from module level into function scope across web/pgadmin/misc/cloud/.

Blueprint and route registrations remain eager, but third-party client libraries are now only imported when a user interacts with a cloud wizard. Subsequent calls remain fast via standard sys.modules caching.

Changes

  • AWS RDS (misc/cloud/rds): Inlined boto3.session.Session in get_regions() and boto3 in RDS._get_aws_client().
  • Azure (misc/cloud/azure): Added _azure_sdk() helper for AzureCliCredential, DeviceCodeCredential, AuthenticationRecord, PostgreSQLManagementClient, ResourceManagementClient, SubscriptionClient, and NameAvailabilityRequest.
  • Google Cloud (misc/cloud/google): Inlined InstalledAppFlow and Request; added _google_sdk() helper for discovery and HttpError. Preserved sys.modules.setdefault('oauth2client', None) at the module top.

Import Time Impact (python -X importtime)

Module Before (ms) After (ms) Reduction
RDS 990.6 ms 338.3 ms 652.3 ms (65.9%)
Azure 1072.6 ms 103.1 ms 969.5 ms (90.4%)
Google Cloud 1051.8 ms 147.0 ms 904.8 ms (86.0%)
Combined (all 3) 1856.1 ms 109.5 ms 1746.6 ms (94.1%)

(Combined import time drops by ~1.75s / 94.1% during startup)

Verification made by my AI agent for the changes:

  • All 24 unit test scenarios in web/pgadmin/misc/cloud/ pass cleanly.
  • Verified that cloud SDKs are absent from sys.modules on blueprint load and resolve properly on demand.
  • pycodestyle passed with 0 errors/warnings.

Partially fixes and addresses #10221

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1655caba-74a4-4cc1-b3d6-9e14498481d4

📥 Commits

Reviewing files that changed from the base of the PR and between bc58657 and 0ff1b7e.

📒 Files selected for processing (3)
  • web/pgadmin/misc/cloud/azure/__init__.py
  • web/pgadmin/misc/cloud/google/__init__.py
  • web/pgadmin/misc/cloud/rds/__init__.py

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


Walkthrough

Azure, Google, and AWS cloud modules now defer heavy SDK imports until related functions execute. Google service and authentication paths use local or cached SDK references. Existing client construction and error handling remain unchanged.

Changes

Cloud SDK import deferral

Layer / File(s) Summary
Azure SDK loading and client wiring
web/pgadmin/misc/cloud/azure/__init__.py
Azure SDK classes now load through _azure_sdk() when authentication, client creation, or cluster-name checks run.
Google SDK loading and service calls
web/pgadmin/misc/cloud/google/__init__.py
Google API modules now load on demand. Authentication flows and service methods use local or cached SDK references.
AWS SDK loading
web/pgadmin/misc/cloud/rds/__init__.py
boto3 imports now occur inside region and client construction functions.

Estimated code review effort: 2 (Simple) | ~15 minutes

Merge Risk: ⚪ Minimal · up to 0ff1b

Cloud SDKs are now loaded when the existing workflows run, reducing startup cost without changing routes, authentication, or client behavior. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: dpage, asheshv

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: deferring cloud SDK imports across AWS RDS, Azure, and Google Cloud.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

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.

1 participant