-
Notifications
You must be signed in to change notification settings - Fork 35
FEAT: Replace bulkcopy kwargs with explicit parameters #420
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2452,7 +2452,18 @@ def nextset(self) -> Union[bool, None]: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def _bulkcopy( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self, table_name: str, data: Iterable[Union[Tuple, List]], **kwargs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| table_name: str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: Iterable[Union[Tuple, List]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| batch_size: Optional[int] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timeout: Optional[int] = 30, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bewithgaurav marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| column_mappings: Optional[List[Tuple[Union[str, int], str]]] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| keep_identity: Optional[bool] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| check_constraints: Optional[bool] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| table_lock: Optional[bool] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| keep_nulls: Optional[bool] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fire_triggers: Optional[bool] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use_internal_transaction: Optional[bool] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): # pragma: no cover | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Perform bulk copy operation for high-performance data loading. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2471,20 +2482,33 @@ def _bulkcopy( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - The number of values in each row must match the number of columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in the target table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| **kwargs: Additional bulk copy options. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| batch_size: Number of rows to send per batch. Default uses server optimal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timeout: Operation timeout in seconds. Default is 30. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| column_mappings: Maps source data columns to target table column names. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Each tuple is (source, target_column_name) where: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - source: Column name (str) or 0-based index (int) in the source data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - source: Column name (str) or 0-based index (int) in the source data | |
| - source: 0-based index (int) in the source data |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The refactor changes behavior by always passing parameters like keep_identity, check_constraints, etc. to pycore_cursor.bulkcopy, even when they are None. Previously, omitted options would not be forwarded at all (via **kwargs), allowing the underlying library defaults to apply. To preserve semantics (and avoid potential TypeError if the core API expects bool), build a kwargs/options dict and only include values that are not None (or change defaults to explicit booleans).
| result = pycore_cursor.bulkcopy( | |
| table_name, | |
| iter(data), | |
| batch_size=batch_size, | |
| timeout=timeout, | |
| column_mappings=column_mappings, | |
| keep_identity=keep_identity, | |
| check_constraints=check_constraints, | |
| table_lock=table_lock, | |
| keep_nulls=keep_nulls, | |
| fire_triggers=fire_triggers, | |
| use_internal_transaction=use_internal_transaction, | |
| bulkcopy_kwargs = {} | |
| if batch_size is not None: | |
| bulkcopy_kwargs["batch_size"] = batch_size | |
| if timeout is not None: | |
| bulkcopy_kwargs["timeout"] = timeout | |
| if column_mappings is not None: | |
| bulkcopy_kwargs["column_mappings"] = column_mappings | |
| if keep_identity is not None: | |
| bulkcopy_kwargs["keep_identity"] = keep_identity | |
| if check_constraints is not None: | |
| bulkcopy_kwargs["check_constraints"] = check_constraints | |
| if table_lock is not None: | |
| bulkcopy_kwargs["table_lock"] = table_lock | |
| if keep_nulls is not None: | |
| bulkcopy_kwargs["keep_nulls"] = keep_nulls | |
| if fire_triggers is not None: | |
| bulkcopy_kwargs["fire_triggers"] = fire_triggers | |
| if use_internal_transaction is not None: | |
| bulkcopy_kwargs["use_internal_transaction"] = use_internal_transaction | |
| result = pycore_cursor.bulkcopy( | |
| table_name, | |
| iter(data), | |
| **bulkcopy_kwargs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're sending appropriate params, resolving this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
batch_sizeis typed asOptional[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 anint, or explicitly support non-integer values and document why).