Skip to content

feat: Improve handling of database drivers with missing dependencies#779

Merged
gfieni merged 3 commits intomasterfrom
feat/database-lazy-import
Mar 13, 2026
Merged

feat: Improve handling of database drivers with missing dependencies#779
gfieni merged 3 commits intomasterfrom
feat/database-lazy-import

Conversation

@gfieni
Copy link
Contributor

@gfieni gfieni commented Mar 13, 2026

This PR improves how database drivers with missing external dependencies are handled.

Detailed changes :

  • Let ImportError propagate from database drivers.
  • Remove eager database driver exports from powerapi.database module.
  • Update CLI DB factories to use lazy imports so missing dependencies are handled at configuration time rather than module import time.
  • Rework unit tests to isolate optional-driver behavior :
    • Split CLI generator tests by database driver. (with automatic skip when dependencies are missing)
    • Use database drivers without external dependencies (csv, socket, json) for generic tests.

gfieni added 3 commits March 11, 2026 15:01
Instead of catching the exception during import of the database driver,
change the behavior to let the `ImportError` exception propagate. This
allow to lazy-import the drivers and gracefully handle the missing
dependencies during the configuration.
Lazily import the database drivers inside the factory methods in order
to gracefully handles failures because of missing dependencies.
- Split the generator tests for databases with external dependencies
- Use builtin database drivers (csv, socket, json) for generic tests
- Update test configuration files
- Remove unused fixtures
@gfieni gfieni self-assigned this Mar 13, 2026
@gfieni gfieni requested a review from a team as a code owner March 13, 2026 11:26
@gfieni gfieni added the enhancement New feature or request label Mar 13, 2026
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 13, 2026

Quality Gate Passed Quality Gate passed

Issues
0 New issues
1 Accepted issue

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@gfieni gfieni merged commit 4d9710e into master Mar 13, 2026
9 checks passed
@gfieni gfieni deleted the feat/database-lazy-import branch March 13, 2026 11:28
@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.28%. Comparing base (ae509e6) to head (9b8912f).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
src/powerapi/cli/generator.py 87.50% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #779      +/-   ##
==========================================
+ Coverage   69.88%   70.28%   +0.40%     
==========================================
  Files          91       91              
  Lines        2919     2908      -11     
==========================================
+ Hits         2040     2044       +4     
+ Misses        879      864      -15     
Files with missing lines Coverage Δ
src/powerapi/database/__init__.py 100.00% <ø> (ø)
src/powerapi/database/mongodb/driver.py 53.96% <100.00%> (+1.72%) ⬆️
src/powerapi/database/opentsdb/driver.py 59.37% <100.00%> (+3.81%) ⬆️
src/powerapi/database/prometheus/driver.py 61.11% <100.00%> (+3.61%) ⬆️
src/powerapi/cli/generator.py 87.14% <87.50%> (+0.01%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant