- 
                Notifications
    
You must be signed in to change notification settings  - Fork 32
 
♻️ [Maintenance] Refactor Payments Domain to Use asyncpg Instead of aiopg #8462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
♻️ [Maintenance] Refactor Payments Domain to Use asyncpg Instead of aiopg #8462
Conversation
          Codecov Report❌ Patch coverage is  Additional details and impacted files@@            Coverage Diff             @@
##           master    #8462      +/-   ##
==========================================
+ Coverage   87.42%   87.97%   +0.54%     
==========================================
  Files        1912     1861      -51     
  Lines       74965    73182    -1783     
  Branches     1333     1063     -270     
==========================================
- Hits        65540    64380    -1160     
+ Misses       9026     8474     -552     
+ Partials      399      328      -71     
 
 Continue to review full report in Codecov by Sentry. 
 🚀 New features to boost your workflow:
  | 
    
b9a0f03    to
    1efb2c3      
    Compare
  
    … consistency in autorecharge API
…to use asyncpg engine
… consistency and update database connection handling to use asyncpg engine
…ne and improve connection handling in tests and payment completion logic
…ency and update references across the codebase
4eeccc2    to
    eccda81      
    Compare
  
    | 
           @mergify queue  | 
    
There was a problem hiding this 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 migrates the payments domain from legacy aiopg to modern asyncpg database access patterns. The refactoring modernizes database interactions by adopting SQLAlchemy's async API throughout the payments system while maintaining backwards compatibility.
- Replace 
aiopg.sa.connection.SAConnectionwithsqlalchemy.ext.asyncio.AsyncConnectionacross all payment modules - Update error handling from 
aiopg_errorstosqlalchemy.excexceptions - Modernize database result handling using SQLAlchemy's async result methods
 
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description | 
|---|---|
| services/web/server/src/simcore_service_webserver/projects/models.py | Remove aiopg imports and type aliases | 
| services/web/server/src/simcore_service_webserver/payments/_onetime_db.py | Migrate to asyncpg engine and async connection patterns | 
| services/web/server/src/simcore_service_webserver/payments/_onetime_api.py | Update database engine usage and model references | 
| services/web/server/src/simcore_service_webserver/payments/_methods_db.py | Comprehensive migration to async patterns with new connection handling | 
| services/web/server/src/simcore_service_webserver/payments/_methods_api.py | Update model type references | 
| services/web/server/src/simcore_service_webserver/payments/_autorecharge_db.py | Migrate autorecharge functionality to async patterns | 
| services/web/server/src/simcore_service_webserver/payments/_autorecharge_api.py | Update model references for consistency | 
| services/web/server/src/simcore_service_webserver/garbage_collector/_core_utils.py | Remove aiopg error handling | 
| services/web/server/src/simcore_service_webserver/garbage_collector/_core_guests.py | Remove aiopg error handling | 
| services/payments/src/simcore_service_payments/db/auto_recharge_repo.py | Update autorecharge statement class name | 
| packages/service-library/src/servicelib/aiohttp/db_asyncpg_engine.py | Modernize app key usage with proper typing | 
| packages/postgres-database/tests/test_utils_payments_autorecharge.py | Comprehensive test migration to async patterns | 
| packages/postgres-database/tests/test_models_payments_transactions.py | Update test patterns for async database operations | 
| packages/postgres-database/src/simcore_postgres_database/utils_payments_autorecharge.py | Rename class for consistency | 
| packages/postgres-database/src/simcore_postgres_database/utils_payments.py | Core migration from aiopg to asyncpg patterns | 
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
        
          
                packages/postgres-database/tests/test_models_payments_transactions.py
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                packages/postgres-database/tests/test_models_payments_transactions.py
              
                Outdated
          
            Show resolved
            Hide resolved
        
      
          
 🟠 Waiting for conditions to match
  | 
    
…ions.py Co-authored-by: Copilot <[email protected]>
…ions.py Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this 🥇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx
          
 | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks



What do these changes do?
This PR migrates database access from
aiopgtoasyncpgin the following components:paymentsdomain within thewebserversimcore_postgres_database.utils_paymentsmodule and its associated test suiteIn detail summary (AI generated)
This pull request refactors the payments database utility and its usage across the codebase to fully adopt SQLAlchemy's async API, removing legacy
aiopgtypes and error handling. It also updates test cases and web server modules to use the new async interfaces and corrects model naming for autorecharge logic. These changes modernize the codebase, improve compatibility with SQLAlchemy, and simplify transaction handling.Database API modernization:
aiopg.sa.connection.SAConnectionand related types withsqlalchemy.ext.asyncio.AsyncConnectionand SQLAlchemy's async result types inutils_payments.py, updating function signatures and result handling accordingly. [1] [2] [3] [4] [5] [6]sqlalchemy.exc.IntegrityErrorinstead of customaiopg_errors.UniqueViolation.Test suite updates:
AsyncEngineand async context management for database connections, replacing legacy connection types and adapting result assertions to new SQLAlchemy row objects. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]Web server module updates:
aiopg_errors.DatabaseErrorin exception handling for guest user and project owner removal logic, relying solely onasyncpgand domain-specific errors. [1] [2] [3]Autorecharge model and API corrections:
PaymentsAutorechargeDBtoPaymentsAutorechargeGetDBand updated all references and API conversion functions to use the new model name, ensuring consistency between DB and API layers. [1] [2] [3] [4] [5] [6]These changes collectively improve code maintainability, test reliability, and compatibility with modern async database patterns.
Related issue/s
How to test
Dev-ops
None