Skip to content

fix: handle zero values for max_retries, initial_backoff, and max_backoff in OpenSearch index_documents - #3432

Open
hsusul wants to merge 1 commit into
aws:mainfrom
hsusul:fix/opensearch-index-documents-zero-retries
Open

fix: handle zero values for max_retries, initial_backoff, and max_backoff in OpenSearch index_documents#3432
hsusul wants to merge 1 commit into
aws:mainfrom
hsusul:fix/opensearch-index-documents-zero-retries

Conversation

@hsusul

@hsusul hsusul commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes an issue in awswrangler.opensearch.index_documents where passing 0 for retry and backoff configuration arguments (max_retries=0, initial_backoff=0, max_backoff=0) resulted in incorrect default fallback assignment and validation bypass.

Root Cause

  1. if use_threads and any([max_retries, initial_backoff, max_backoff]): evaluated any([0, None, None]) as False because 0 is falsey in Python. As a result, passing max_retries=0 when use_threads=True failed to trigger exceptions.InvalidArgumentCombination.
  2. When use_threads=False, bulk_kwargs["max_retries"] = 5 if not max_retries else max_retries evaluated not 0 as True, overriding max_retries=0 to 5. Similarly, initial_backoff=0 was overridden to 2 and max_backoff=0 was overridden to 600.

Solution

  • Updated the use_threads validation check to any(x is not None for x in (max_retries, initial_backoff, max_backoff)) to properly check for explicit argument presence.
  • Updated default bulk_kwargs assignments to check x is None instead of not x, ensuring explicit zero values (0) are preserved.
  • Added unit tests with mocked OpenSearch clients to verify both unthreaded zero-value propagation and threaded exception raising.

Validation Results

  • poetry run pytest tests/unit/test_opensearch.py -k "test_index_documents_zero_retries" passed cleanly.
  • poetry run pytest tests/unit/test_moto.py passed cleanly (46 passed).
  • poetry run ruff check and poetry run ruff format --check passed cleanly.

AWS Integration Tests Not Run

  • Tests in tests/unit/test_opensearch.py requiring live AWS OpenSearch domain infrastructure were not run as they require live AWS credentials and CloudFormation stack resources.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

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.

1 participant