Skip to content

Conversation

@bewithgaurav
Copy link
Collaborator

@bewithgaurav bewithgaurav commented Jan 30, 2026

Work Item / Issue Reference

AB#41884


Summary

Implements Revision 2 of the BulkCopy API spec from community feedback in #414.

Replaces **kwargs with explicit, type-hinted parameters for better IDE autocomplete and discoverability

Changes

API Signature

def _bulkcopy(
    self,
    table_name: str,
    data: Iterable[Union[Tuple, List]],
    batch_size: int = 0,
    timeout: int = 30,
    column_mappings: Optional[Union[List[str], List[Tuple[int, str]]]] = None,
    keep_identity: bool = False,
    check_constraints: bool = False,
    table_lock: bool = False,
    keep_nulls: bool = False,
    fire_triggers: bool = False,
    use_internal_transaction: bool = False,
) -> Dict[str, Any]

What Changed

Aspect Before After
Parameter style **kwargs Explicit parameters
IDE support No autocomplete ✅ Full autocomplete
Type safety Optional[bool] = None bool = False
batch_size Optional[int] = None int = 0 (0 = server optimal)
column_mappings List[Tuple[Union[str, int], str]] Union[List[str], List[Tuple[int, str]]]

Column Mappings

Per @amachanic's feedback, now supports simpler format:

Simple - List[str]:

column_mappings = ['UserID', 'FirstName', 'Email']

Advanced - List[Tuple[int, str]]:

column_mappings = [(0, 'UserID'), (1, 'FirstName'), (3, 'Email')]

@github-actions github-actions bot added the pr-size: small Minimal code update label Jan 30, 2026
…IDE discoverability

- All options now explicit in function signature
- Pass params directly to pycore (no kwargs dict conversion)
- Matches mssql-tds explicit params API

Based on community feedback from discussion #414
@bewithgaurav bewithgaurav force-pushed the bewithgaurav/fix-bulkcopy-kwargs branch from c90f0f1 to fa2eab4 Compare January 30, 2026 12:39
@bewithgaurav bewithgaurav marked this pull request as ready for review January 30, 2026 12:40
Copilot AI review requested due to automatic review settings January 30, 2026 12:40
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

Refactors Cursor._bulkcopy to replace **kwargs bulk-copy options with an explicit, type-hinted parameter list and updated docstring.

Changes:

  • Replaced **kwargs in _bulkcopy with explicit parameters (e.g., batch_size, timeout, column_mappings, and bulk-copy flags).
  • Expanded _bulkcopy docstring to document supported bulk copy options.
  • Updated the pycore_cursor.bulkcopy(...) invocation to pass the new explicit parameters.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

self,
table_name: str,
data: Iterable[Union[Tuple, List]],
batch_size: Optional[int] = None,
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

batch_size is typed as Optional[int], but the validation accepts floats (isinstance(batch_size, (int, float))) while the error message says “positive integer”. Please align the type hint, validation, and message (either require an int, or explicitly support non-integer values and document why).

Suggested change
batch_size: Optional[int] = None,
batch_size: Optional[Union[int, float]] = None,

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

github-actions bot commented Feb 1, 2026

📊 Code Coverage Report

🔥 Diff Coverage

100%


🎯 Overall Coverage

76%


📈 Total Lines Covered: 5472 out of 7137
📁 Project: mssql-python


Diff Coverage

Diff: main...HEAD, staged and unstaged changes

No lines with coverage information in this diff.


📋 Files Needing Attention

📉 Files with overall lowest coverage (click to expand)
mssql_python.pybind.logger_bridge.hpp: 58.8%
mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.row.py: 66.2%
mssql_python.pybind.ddbc_bindings.cpp: 69.3%
mssql_python.pybind.ddbc_bindings.h: 69.7%
mssql_python.pybind.connection.connection.cpp: 75.3%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.pybind.connection.connection_pool.cpp: 79.6%
mssql_python.connection.py: 84.1%
mssql_python.cursor.py: 84.7%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

After Saurabh's review, Rust bulkcopy now uses direct types (bool, usize)
instead of Option<T>. Python must not pass None values - instead omit
the kwarg and let PyO3 use its defaults.
@subrata-ms subrata-ms self-requested a review February 2, 2026 05:29
return True

def _bulkcopy(
self, table_name: str, data: Iterable[Union[Tuple, List]], **kwargs
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please provide more details in the PR summary for this change?
This API change may not be scalable in future as any new parameter addition need to go through the API contract change which is not advisable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The conversation around new API spec is happening in Github Discussions topic #414
I'll update the PR summary with the new spec details and link to the above discussion shortly
will ping once done

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done - updated, pls recheck and let me know if you have any comments

@bewithgaurav bewithgaurav marked this pull request as draft February 2, 2026 07:10
- batch_size: int = 0 (0 means server optimal)
- timeout: int = 30
- column_mappings: Optional[Union[List[str], List[Tuple[int, str]]]] = None
- All boolean flags: bool = False (not Optional[bool] = None)

Updated docstring with two column_mappings formats:
- Simple: List[str] - position = source index
- Advanced: List[Tuple[int, str]] - explicit (index, column) mapping

Simplified bulkcopy call to pass params directly (no kwargs dict)
since Rust API now uses explicit defaults per Saurabh's review.
@bewithgaurav bewithgaurav changed the title FEAT: Replace bulkcopy kwargs with explicit parameters FEAT: Explicit parameters and improved type hints for bulkcopy Feb 2, 2026
@bewithgaurav bewithgaurav marked this pull request as ready for review February 2, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: small Minimal code update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants