Skip to content

Conversation

@bewithgaurav
Copy link
Collaborator

Work Item / Issue Reference

AB#<WORK_ITEM_ID>

GitHub Issue: #182


Summary

This pull request makes improvements to the cursor resource management and error handling in the mssql_python/cursor.py module. The main changes include making the cursor close operation idempotent, refining exception types, and improving logging during cleanup. These updates help ensure more robust and predictable behavior when working with cursors.

Error handling improvements:

  • Changed the exception raised when attempting to close an already closed cursor from a generic Exception to a more specific ProgrammingError, providing clearer feedback to users.
  • Updated the import statement to use ProgrammingError instead of InterfaceError, aligning with the new error handling approach.

Resource cleanup and logging:

  • Improved the destructor (__del__) to check for the correct closed attribute and made sure no exception is raised if the cursor is already closed, enhancing reliability during garbage collection.
  • Changed the logging level in the destructor from 'error' to 'debug' for exceptions during cleanup, reducing unnecessary noise in error logs.

Copilot AI review requested due to automatic review settings August 18, 2025 07:19
@github-actions github-actions bot added the pr-size: small Minimal code update label Aug 18, 2025
Copy link
Contributor

Copilot AI left a 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 improves cursor resource management and error handling in the mssql_python cursor module. The changes make cursor operations more robust by implementing idempotent close behavior and better cleanup procedures.

  • Enhanced cursor close operation to be idempotent and use more specific exception types
  • Fixed destructor to properly check the closed attribute instead of _closed
  • Improved logging during cleanup by reducing error noise to debug level

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions github-actions bot added pr-size: small Minimal code update and removed pr-size: small Minimal code update labels Aug 18, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: small Minimal code update labels Aug 18, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Aug 18, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Aug 18, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Aug 18, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Aug 18, 2025
Copy link
Contributor

@sumitmsft sumitmsft left a comment

Choose a reason for hiding this comment

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

Left a couple of comments.

@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 4, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 4, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 5, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 5, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 5, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 5, 2025
@bewithgaurav bewithgaurav merged commit 4b42f8c into main Sep 5, 2025
18 checks passed
@bewithgaurav bewithgaurav changed the title FIX: Closed Attribute in cursor __del__ FIX: Cursor resource management, error handling & logging Sep 8, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: medium Moderate update size

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make cursor finalizer shutdown cleanup idempotent and lower log level when cursor is already closed

4 participants