Skip to content

Conversation

@jahnvi480
Copy link
Contributor

@jahnvi480 jahnvi480 commented Aug 21, 2025

Work Item / Issue Reference

AB#34913
AB#34914
AB#34915
AB#34916


Summary

This pull request adds a flexible output converter system to the database connection, allowing custom Python functions to be registered for converting SQL data types when fetching results. It introduces new methods for managing these converters and updates the row handling logic to apply them automatically. Comprehensive tests are added to verify correct registration, retrieval, removal, and integration of output converters, including edge cases and chaining behavior.

Core output converter system:

  • Added methods to Connection (add_output_converter, get_output_converter, remove_output_converter, clear_output_converters) for registering and managing output converter functions for specific SQL types. These converters are called when values of the registered SQL type are read from the database. (mssql_python/connection.py)
  • Updated the Row class to apply registered output converters automatically to values fetched from the database, with fallback logic for string types and robust error handling. (mssql_python/row.py)

Testing and validation:

  • Added extensive tests for output converter management, including adding, retrieving, removing, clearing, chaining, temporary replacement, and integration during data fetching. Tests also cover edge cases such as handling NULL values and using multiple converters at once. (tests/test_003_connection.py)
  • Introduced helper converter functions for specific SQL types (e.g., DATETIMEOFFSET and custom string handling) to support and validate the new converter system in tests. (tests/test_003_connection.py)

Test and utility enhancements:

  • Imported additional modules (struct, datetime, timezone, and constants) to support new test cases and converter logic. (tests/test_003_connection.py)

@github-actions github-actions bot added the pr-size: medium Moderate update size label Aug 21, 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 few comments.

@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 15, 2025
sumitmsft
sumitmsft previously approved these changes Sep 16, 2025
@jahnvi480 jahnvi480 changed the base branch from jahnvi/connection_execute to main September 18, 2025 08:14
@jahnvi480 jahnvi480 dismissed sumitmsft’s stale review September 18, 2025 08:14

The base branch was changed.

Copilot AI review requested due to automatic review settings September 18, 2025 09:06
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 pull request adds a flexible output converter system to the mssql-python database connection, allowing custom Python functions to be registered for converting SQL data types when fetching results. The implementation includes comprehensive thread-safe methods for managing converters and robust integration with the row handling logic.

  • Adds connection-level output converter management methods (add, get, remove, clear) with thread safety
  • Updates Row class to automatically apply registered output converters during data fetching with error handling
  • Includes extensive testing for converter registration, retrieval, integration, and edge cases

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
mssql_python/connection.py Adds output converter management methods and convenience execute() method with thread-safe implementation
mssql_python/row.py Updates Row class to apply output converters automatically with fallback logic and error handling
tests/test_003_connection.py Adds comprehensive tests for output converter functionality including helper functions and edge cases
tests/test_004_cursor.py Reorganizes test functions by moving them to different locations within the file
tests/test_001_globals.py Adds duplicate test for decimal separator functionality

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: large Substantial code update and removed pr-size: medium Moderate update size labels Sep 18, 2025
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 18, 2025
@jahnvi480 jahnvi480 merged commit 8fbf45a into main Sep 18, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: large Substantial code update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants