Skip to content

BulkInsert failure (and bad error) #235

@ayende

Description

@ayende

Using this file:

small-cars.json

The following code will error (and give a mysterious error)

import json
from ravendb import DocumentStore
from pathlib import Path

class Car:
    def __init__(self, path, vec):
        self.path = path
        self.embeddings = vec

def initialize_store():
    store = DocumentStore(
        urls=["http://live-test.ravendb.net"],  
        database="Cars"      
    )
    store.initialize()
    return store

def read_json_array(filename):
    with open(filename, 'r') as f:
        data = json.load(f) 
        for item in data:   
            yield item

if __name__ == "__main__":
    with initialize_store() as store:
        with store.bulk_insert() as bulk_insert:
            cars = []
            for i in range(500):
                for c in read_json_array("small-cars.json"):
                    bulk_insert.store(Car(c["name"], c["vector"]))

Output:

Traceback (most recent call last):
  File "F:\images.py\load.py", line 26, in <module>
    with store.bulk_insert() as bulk_insert:
         ^^^^^^^^^^^^^^^^^^^
  File "F:\images.py\.venv\Lib\site-packages\ravendb\documents\bulk_insert_operation.py", line 182, in __exit__
    self._throw_bulk_insert_aborted(e, flush_ex)
  File "F:\images.py\.venv\Lib\site-packages\ravendb\documents\bulk_insert_operation.py", line 194, in _throw_bulk_insert_aborted
    raise BulkInsertAbortedException("Failed to execute bulk insert", e or flush_ex)
ravendb.exceptions.documents.bulkinsert.BulkInsertAbortedException: ('Failed to execute bulk insert', JSONDecodeError('Expecting value: line 1 column 1 (char 0)'))

Metadata

Metadata

Assignees

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