Skip to content
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

New drivers #1324

Merged
merged 4 commits into from
Oct 24, 2024
Merged

New drivers #1324

merged 4 commits into from
Oct 24, 2024

Conversation

phenobarbital
Copy link
Owner

@phenobarbital phenobarbital commented Oct 24, 2024

Summary by Sourcery

Refactor PostgreSQL driver to use a context manager for error handling in copy operations, improving code consistency and reliability. Enhance transaction management by resetting transaction state after commit and rollback. Improve RethinkDB driver with detailed logging for batch inserts. Update test examples to use transactions for copy operations and correct the database URL. Remove unused code and ensure proper closure of the event loop in test examples.

Enhancements:

  • Refactor error handling in PostgreSQL driver by introducing a context manager to handle copy operation errors consistently.
  • Improve transaction management in PostgreSQL driver by resetting the transaction state after commit and rollback operations.
  • Enhance RethinkDB driver with detailed logging for batch insert operations.

Tests:

  • Update test examples to use transactions for copy operations, improving reliability and error handling.

Chores:

  • Update the database URL in test examples to reflect the correct database name.
  • Remove unused code and close the event loop properly in test examples.

Copy link
Contributor

sourcery-ai bot commented Oct 24, 2024

Reviewer's Guide by Sourcery

This PR introduces error handling improvements and transaction management enhancements in the database drivers. The main changes include a new context manager for PostgreSQL copy operations error handling, transaction cleanup improvements, and some code refactoring for better maintainability.

Sequence diagram for PostgreSQL copy operations with error handling

sequenceDiagram
    participant User
    participant App
    participant PostgreSQL

    User->>App: Initiate copy operation
    App->>PostgreSQL: Begin transaction
    App->>PostgreSQL: Perform copy operation
    App->>App: Handle errors with handle_copy_errors
    alt Success
        PostgreSQL-->>App: Copy operation successful
        App->>PostgreSQL: Commit transaction
    else Error
        PostgreSQL-->>App: Error occurs
        App->>User: Notify error
        App->>PostgreSQL: Rollback transaction
    end
Loading

Updated class diagram for PostgreSQL driver

classDiagram
    class PostgreSQLDriver {
        - _transaction
        + transaction()
        + commit()
        + rollback()
        + cursor(sentence, params, kwargs)
        + handle_copy_errors(operation_name)
        + copy_from_table(table, schema, output, file_type, columns)
        + copy_to_table(table, schema, source, file_type, columns)
        + copy_into_table(table, schema, source, columns)
    }
    note for PostgreSQLDriver "Added handle_copy_errors for error management in copy operations"
Loading

File-Level Changes

Change Details Files
Introduced a new async context manager for handling PostgreSQL copy operation errors
  • Created handle_copy_errors context manager to centralize error handling logic
  • Refactored copy_from_table, copy_to_table, and copy_into_table to use the new context manager
  • Improved error messages and exception handling consistency
asyncdb/drivers/pg.py
Enhanced transaction management in PostgreSQL driver
  • Added transaction cleanup by setting _transaction to None after commit/rollback
  • Updated transaction handling in copy operations
asyncdb/drivers/pg.py
Improved RethinkDB batch operation logging and response formatting
  • Added debug logging for batch progress
  • Improved batch operation result formatting
asyncdb/drivers/rethink.py
Updated example code and configuration
  • Modified database connection settings
  • Updated transaction handling in examples
  • Improved cleanup handling in main execution
examples/test_asyncdb.py
Bumped package version
  • Incremented version from 2.9.5 to 2.9.6
asyncdb/version.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @phenobarbital - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Hardcoded database credentials found in the code. (link)

Overall Comments:

  • Consider keeping pool.terminate() before loop.close() to ensure proper cleanup of database connections
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🔴 Security: 1 blocking issue
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

asyncdb/drivers/pg.py Outdated Show resolved Hide resolved
examples/test_asyncdb.py Show resolved Hide resolved
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@phenobarbital phenobarbital merged commit ce18ef0 into master Oct 24, 2024
2 checks passed
@phenobarbital phenobarbital deleted the new-drivers branch October 24, 2024 21:29
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