Skip to content

fix(documents): type the server's batch_size in import parameters - #160

Open
theluckystrike wants to merge 1 commit into
typesense:masterfrom
theluckystrike:fix/import-batch-size-type
Open

theluckystrike wants to merge 1 commit into
typesense:masterfrom
theluckystrike:fix/import-batch-size-type

Conversation

@theluckystrike

Copy link
Copy Markdown

Fixes #124.

import_(docs, batch_size=42) does not send batch_size to the server. That argument splits the list into requests of that size on the client. To set the server's batch_size query parameter you pass it in import_parameters, which works at run time, but none of the import parameter types had a batch_size key, so a type checker rejects it.

What I changed:

  • New DocumentImportWriteParameters (extends DocumentWriteParameters) with batch_size: NotRequired[int].
  • The return_id, return_doc and return_doc + return_id import types extend it, and DocumentImportParameters uses it in place of DocumentWriteParameters. The plain import_ overload and the create_many cast use it too.
  • The import_ docstring now says which batch_size goes where.
  • Edited in async_/ and regenerated sync/ with utils/run-unasync.py.

Tests: new tests/import_parameters_test.py checks the types, that import_parameters={"batch_size": 42} reaches the query string, and that the batch_size argument splits the requests and is not sent. It fails on master (the type does not exist) and passes with the change. mypy src/typesense, ruff check and ruff format --check on the changed files pass, and the mock-transport suites pass. Tests that need a running Typesense server were not run locally.

Fixes typesense#124. The batch_size argument of import_ splits the list on the
client and is never sent to the server, while the import parameter types
had no batch_size key, so the documented server parameter failed the type
check. Add DocumentImportWriteParameters with batch_size, use it for the
plain import and the return_id/return_doc variants, and document the
difference in the import_ docstring.

This branch has not been deployed

No deployments
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.

documents.Documents.import_() batch_size argument is ignored, type of import_parameters is missing batch_size

1 participant