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

refactor: refactored basedatabase methods #1400

Merged
merged 6 commits into from
Sep 28, 2024
Merged

Conversation

weibullguy
Copy link
Collaborator

@weibullguy weibullguy commented Sep 19, 2024

Does this PR introduce a breaking change?

  • Yes
  • No

Describe the purpose of this pull request.

Refactor database classes for maintainability.

Describe how this was implemented.

Use ChatGPT to help refactor classes.

Describe any particular area(s) reviewers should focus on.

None

Pull Request Checklist

  • Code Style

    • Code is following code style guidelines.
  • Static Checks

    • Failing static checks are only applicable to code outside the scope of
      this PR.
  • Tests

    • At least one test for all newly created functions/methods?
  • Chores

    • Issue(s) have been raised for problem areas outside the scope of
      this PR. These problem areas have been decorated with an ISSUE: # comment.

Summary by Sourcery

Refactor the BaseDatabase class to improve maintainability and error handling by introducing helper methods for database connections and query execution. Simplify error handling by consolidating exception management into a single method. Update tests to align with the refactored logic and verify the new error handling behavior.

Enhancements:

  • Refactor database connection logic to improve maintainability and error handling by introducing helper methods for building database URLs and executing queries.
  • Simplify error handling in database operations by consolidating exception handling into a single method.
  • Improve the clarity and robustness of database session management by refactoring connection and session creation logic.
  • Enhance the database query execution by adding a method to filter out system databases and return only relevant ones.

Tests:

  • Update test cases to reflect changes in database connection and error handling logic, ensuring that exceptions are raised correctly for invalid operations.
  • Modify tests to verify the new error messages and logging behavior introduced in the refactored database methods.

Copy link
Contributor

sourcery-ai bot commented Sep 19, 2024

Reviewer's Guide by Sourcery

This pull request refactors the basedatabase methods to improve maintainability and error handling. The changes include restructuring the database connection process, enhancing error handling, and improving code organization.

File-Level Changes

Change Details Files
Refactored database connection process
  • Created a new _connect_to_db helper method
  • Implemented a more robust connection process with better error handling
  • Added a new do_build_database_url method to construct database URLs
src/ramstk/models/db/basedatabase.py
Enhanced error handling throughout the BaseDatabase class
  • Introduced a new do_handle_db_error method for centralized error handling
  • Updated various methods to use the new error handling approach
  • Improved error messages and logging
src/ramstk/models/db/basedatabase.py
Improved code organization and readability
  • Broke down large methods into smaller, more focused functions
  • Added type hints and improved docstrings
  • Removed redundant code and simplified logic in several methods
src/ramstk/models/db/basedatabase.py
Updated tests to reflect changes in the BaseDatabase class
  • Modified existing tests to work with the refactored code
  • Added new tests for newly introduced methods
  • Updated error handling expectations in tests
tests/db/test_base.py
Modified DataAccessError exception
  • Changed DataAccessError to inherit from Exception instead of RAMSTKError
  • Made the error message parameter optional
src/ramstk/exceptions.py

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

@github-actions github-actions bot added the type: refactor Issue or PR dealing with refactoring of RAMSTK code. label Sep 19, 2024
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 @weibullguy - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding more specific exception handling in some areas to avoid masking unexpected errors. For example, in the do_connect method, you might want to catch and handle OperationalError separately from other potential exceptions.
  • Some valuable comments have been removed during the refactoring. Consider keeping or rephrasing comments that provide important context, especially for complex operations.
  • The test suite has been modified significantly. Ensure that test coverage is maintained or improved, particularly for newly introduced methods like do_build_database_url and do_filter_system_databases.
Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 6 issues found
  • 🟡 Complexity: 1 issue found
  • 🟢 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 to tell me if it was helpful.

src/ramstk/models/db/basedatabase.py Outdated Show resolved Hide resolved
src/ramstk/models/db/basedatabase.py Show resolved Hide resolved
src/ramstk/models/db/basedatabase.py Show resolved Hide resolved
src/ramstk/models/db/basedatabase.py Show resolved Hide resolved
tests/db/test_base.py Outdated Show resolved Hide resolved
tests/db/test_base.py Outdated Show resolved Hide resolved
tests/db/test_base.py Outdated Show resolved Hide resolved
tests/db/test_base.py Outdated Show resolved Hide resolved
tests/db/test_base.py Show resolved Hide resolved
src/ramstk/models/db/basedatabase.py Show resolved Hide resolved
@weibullguy weibullguy merged commit 281215f into master Sep 28, 2024
17 of 20 checks passed
@trafico-bot trafico-bot bot added the endgame: merged Pull Request has been merged successfully label Sep 28, 2024
@weibullguy weibullguy deleted the refactor/database_classes branch September 28, 2024 17:18
@weibullguy weibullguy added priority: low Issue or PR is low priority. status: closed Pull Request is complete and integrated or closed for anther reason. labels Sep 28, 2024
@trafico-bot trafico-bot bot removed the status: closed Pull Request is complete and integrated or closed for anther reason. label Sep 28, 2024
@weibullguy weibullguy added the status: closed Pull Request is complete and integrated or closed for anther reason. label Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
endgame: merged Pull Request has been merged successfully priority: low Issue or PR is low priority. status: closed Pull Request is complete and integrated or closed for anther reason. type: refactor Issue or PR dealing with refactoring of RAMSTK code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant