Skip to content

Conversation

@cesarcoatl
Copy link
Member

@cesarcoatl cesarcoatl commented Sep 4, 2025

Summary by Sourcery

Introduce a TransactionManager context manager to simplify transaction handling, update the stub files to reflect the new context manager and refactor parameter stubs to use a common base class, and add a style enforcement environment for stubs in tox.ini.

New Features:

  • Introduce TransactionManager context manager for database transactions
  • Add TransactionManager stub definition in the type stubs

Enhancements:

  • Refactor stub definitions by introducing a shared _Param base class and having InParam and OutParam inherit from it

CI:

  • Add a style testenv in tox.ini for formatting and linting stubs with Black, isort, and Flake8

Co-authored-by: lokomoti <40903296+lokomoti@users.noreply.github.com>
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 4, 2025

Reviewer's Guide

This PR introduces a TransactionManager context manager in the core DB module for automatic transaction lifecycle handling, refactors type stubs to centralize parameter behavior in a base class and mirror new functionality, and adds a style test environment in stubs/tox.ini for automated stub formatting checks.

File-Level Changes

Change Details Files
Add TransactionManager context manager for database transactions
  • Store database, isolation level, timeout and generate transaction_id in init
  • Begin transaction in enter via system.db.beginTransaction
  • Commit or rollback based on exception in exit and always close transaction
incendium/src/incendium/db.py
Revise stub definitions to reflect new classes and shared parameter base
  • Introduce _Param base class and deprecate standalone Param stub
  • Adjust InParam and OutParam to inherit from _Param
  • Add TransactionManager stub with init, enter, and exit signatures
incendium-stubs/stubs/incendium/db.pyi
Configure style test environment for stubs
  • Add [testenv:style] with black, isort, flake8 and flake8-pyi dependencies
  • Define commands for automated formatting and linting
incendium-stubs/tox.ini

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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

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 there - I've reviewed your changes - here's some feedback:

  • Wrap commitTransaction and rollbackTransaction calls in a try/finally to ensure closeTransaction is always invoked even if commit or rollback raises.
  • Consider using None rather than an empty string as the default for the database parameter to better represent “no override” and align with the Optional[str] type hint.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Wrap commitTransaction and rollbackTransaction calls in a try/finally to ensure closeTransaction is always invoked even if commit or rollback raises.
- Consider using None rather than an empty string as the default for the database parameter to better represent “no override” and align with the Optional[str] type hint.

## Individual Comments

### Comment 1
<location> `incendium/src/incendium/db.py:206` </location>
<code_context>
         super(OutParam, self).__init__(name_or_index, type_code)


+class TransactionManager(object):
+    """Database transaction context manager."""
+
</code_context>

<issue_to_address>
Consider handling exceptions during transaction commit/rollback more robustly.

Ensure system.db.closeTransaction is always called, even if commit or rollback raise exceptions, to prevent resource leaks.
</issue_to_address>

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.

super(OutParam, self).__init__(name_or_index, type_code)


class TransactionManager(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Consider handling exceptions during transaction commit/rollback more robustly.

Ensure system.db.closeTransaction is always called, even if commit or rollback raise exceptions, to prevent resource leaks.

@cesarcoatl cesarcoatl merged commit ed835d7 into main Sep 4, 2025
8 checks passed
@cesarcoatl cesarcoatl deleted the feat/db/TransactionManager branch September 4, 2025 21:43
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.

2 participants