Skip to content

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

@salomvary

Description

@salomvary

Steps to reproduce:

Create a file named bug.py with the following contents:

import logging
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)

import typesense
from typesense.exceptions import TypesenseClientError
client = typesense.Client({
    'api_key': 'abcd',
    'nodes': [{
        'host': 'localhost',
        'port': '8108',
        'protocol': 'http'
    }],
    'connection_timeout_seconds': 2
})

try:
	client.collections["test"].documents.import_([{"id":1}], batch_size=42)
except:
	pass

try:
	client.collections["test"].documents.import_([{"id":1}], import_parameters=dict(batch_size=42))
except:
	pass
uv init
uv add typesense
uv run bug.py 2>&1 | grep 'HTTP Request'

Outputs:

INFO:httpx:HTTP Request: POST http://localhost:8108/collections/test/documents/import "HTTP/1.1 401 Unauthorized"
INFO:httpx:HTTP Request: POST http://localhost:8108/collections/test/documents/import?batch_size=42 "HTTP/1.1 401 Unauthorized"

Documentation recommends the right thing:
https://typesense.org/docs/30.1/api/documents.html#index-multiple-documents

But the Python signature contradicts:

https://github.com/typesense/typesense-python/blob/master/src/typesense/sync/documents.py#L226-L231

And if someone uses DocumentWriteParameters for import_parameters a type checker will complain that there is no batch_size in DocumentWriteParameters which is true for the type, but wrong run-time as this is the only way to pass in a batch_size that will be added to the request query string:

class DocumentWriteParameters(DirtyValuesParameters):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions