Skip to content

fix(python): add warning in replace_all_objects for empty objects - #6611

Merged
eric-zaharia merged 3 commits into
mainfrom
port/replaceallobjects-empty-warning-20260626/python
Jul 6, 2026
Merged

eric-zaharia merged 3 commits into
mainfrom
port/replaceallobjects-empty-warning-20260626/python

Conversation

@eric-zaharia

@eric-zaharia eric-zaharia commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

🧭 What and Why

šŸŽŸ JIRA Ticket: API-500

Mirrors #6607 for the Python client: logs a warning when replace_all_objects (or replace_all_objects_with_transformation) is called with an empty list of objects, which would otherwise copy settings, batch zero records, and move the temp index over the source — silently emptying the index. Behavior is unchanged.

Changes included:

  • replace_all_objects and replace_all_objects_with_transformation now emit a logging.getLogger(__name__).warning(...) naming the affected index when called with an empty objects collection. logging.warning never raises, so an empty call still proceeds with the copy → batch → move sequence exactly as before.
  • The empty check uses a collections.abc.Sized guard (isinstance(objects, Sized) and len(objects) == 0) so a lazy iterable is never consumed or materialized; objects is passed onward untouched. An empty generator goes unwarned by design (no way to test it without consuming it).
  • Added a Warning: docstring note to both methods so the footgun surfaces on IDE hover.
  • import logging and from collections.abc import Sized are scoped inside the helper bodies to avoid adding unused imports to other generated clients.

Usage

# Logs a WARNING and proceeds to empty the "products" index:
client.replace_all_objects("products", [])

# Unaffected — normal replace:
client.replace_all_objects("products", [{"objectID": "1", "name": "shoe"}])

Existing call sites are unaffected — this only adds a logging warning when the list is empty, and never consumes a lazy iterable.

@algolia-api-clients-automation-bot

algolia-api-clients-automation-bot Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

āœ”ļø Code generated!

Name Link
šŸŖ“ Triggered by bed1f5916d5a222d952c9e01a10a8af3287d6c4a
šŸƒ Generated commit c3c55129faf3fcca1af4c3e692baa27f7182bfbd
🌲 Generated branch generated/port/replaceallobjects-empty-warning-20260626/python
šŸ“Š Benchmark results

Benchmarks performed on the method using a mock server, the results might not reflect the real-world performance.

Language Req/s
python 1362

@eric-zaharia
eric-zaharia marked this pull request as ready for review June 26, 2026 09:21
@eric-zaharia
eric-zaharia requested a review from a team as a code owner June 26, 2026 09:21
@eric-zaharia eric-zaharia self-assigned this Jun 26, 2026
eric-zaharia added a commit that referenced this pull request Jun 26, 2026
…ty-check

Avoid enumerating non-ICollection IEnumerable inputs via .Any(), which would
double-enumerate (and potentially drop records from) one-shot sequences.
Matches the Python reference (#6611), which only warns for Sized inputs.
@eric-zaharia
eric-zaharia enabled auto-merge (squash) July 6, 2026 10:40
@eric-zaharia
eric-zaharia merged commit 915cb46 into main Jul 6, 2026
16 checks passed
@eric-zaharia
eric-zaharia deleted the port/replaceallobjects-empty-warning-20260626/python branch July 6, 2026 11:07
algolia-api-clients-automation-bot Bot added a commit that referenced this pull request Jul 6, 2026
) (generated) [skip ci]

Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-java that referenced this pull request Jul 6, 2026
…nerated)

algolia/api-clients-automation#6611

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-javascript that referenced this pull request Jul 6, 2026
…nerated)

algolia/api-clients-automation#6611

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-kotlin that referenced this pull request Jul 6, 2026
…nerated)

algolia/api-clients-automation#6611

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-php that referenced this pull request Jul 6, 2026
…nerated)

algolia/api-clients-automation#6611

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-python that referenced this pull request Jul 6, 2026
…nerated)

algolia/api-clients-automation#6611

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
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.

2 participants