# Upsert fails with a numeric value fields - Python lib bug

**URL:** <https://community.pinecone.io/t/upsert-fails-with-a-numeric-value-fields-python-lib-bug/1892>\
**Category:** Support\
**Created:** [May 17, 2023, 6:51pm UTC](https://community.pinecone.io/t/upsert-fails-with-a-numeric-value-fields-python-lib-bug/1892 "2023-05-17T18:51:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kshrivastava](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/kshrivastava/32/551_2.png) [@kshrivastava](https://community.pinecone.io/u/kshrivastava)\
**Post date:** [May 17, 2023, 6:51pm UTC](https://community.pinecone.io/t/upsert-fails-with-a-numeric-value-fields-python-lib-bug/1892/1 "2023-05-17T18:51:32Z")

</div>

`check_validations` function in `\site-packages\pinecone\core\client\model_utils.py` incorrectly mentions “input\_values (list/str/int/float/date/datetime): the values that we are checking.”  
You can’t check len(input\_values) for int values.  
ERROR: TypeError: object of type ‘int’ has no len()

---

<div class="post-metadata">

**Author:** ![Cory\_Pinecone](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/cory_pinecone/32/1712_2.png) [@Cory\_Pinecone](https://community.pinecone.io/u/Cory_Pinecone)\
**Post date:** [May 17, 2023, 11:18pm UTC](https://community.pinecone.io/t/upsert-fails-with-a-numeric-value-fields-python-lib-bug/1892/2 "2023-05-17T23:18:28Z")

</div>

Hi @kshrivastava. Can you share the full stack trace for the error you’re seeing? That’ll help us see where in the code the problem is so we can fix it.

Thanks.

---

<div class="post-metadata">

**Author:** ![kshrivastava](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/kshrivastava/32/551_2.png) [@kshrivastava](https://community.pinecone.io/u/kshrivastava)\
**Post date:** [May 17, 2023, 11:23pm UTC](https://community.pinecone.io/t/upsert-fails-with-a-numeric-value-fields-python-lib-bug/1892/3 "2023-05-17T23:23:25Z")

</div>

Traceback (most recent call last):  
File “\HRQA.py”, line 143, in   
index.upsert(vectors=to\_upsert)  
File “\Python\Python39\lib\site-packages\pinecone\core\utils\error\_handling.py”, line 17, in inner\_func  
return func(\*args, \*\*kwargs)  
File “\Python\Python39\lib\site-packages\pinecone\index.py”, line 147, in upsert  
return self.\_upsert\_batch(vectors, namespace, \_check\_type, \*\*kwargs)  
File “\Python\Python39\lib\site-packages\pinecone\index.py”, line 233, in \_upsert\_batch  
vectors=list(map(\_vector\_transform, vectors)),  
File “\Python\Python39\lib\site-packages\pinecone\index.py”, line 226, in \_vector\_transform  
return Vector(id=id, values=values, metadata=metadata or {}, \_check\_type=\_check\_type)  
File “\Python\Python39\lib\site-packages\pinecone\core\client\model\_utils.py”, line 49, in wrapped\_init  
return fn(\_self, \*args, \*\*kwargs)  
File “\Python\Python39\lib\site-packages\pinecone\core\client\model\vector.py”, line 280, in **init**  
self.id = id  
File “\Python\Python39\lib\site-packages\pinecone\core\client\model\_utils.py”, line 188, in **setattr**  
self[attr] = value  
File “\Python\Python39\lib\site-packages\pinecone\core\client\model\_utils.py”, line 488, in **setitem**  
self.set\_attribute(name, value)  
File “\Python\Python39\lib\site-packages\pinecone\core\client\model\_utils.py”, line 170, in set\_attribute  
check\_validations(  
File “\Python\Python39\lib\site-packages\pinecone\core\client\model\_utils.py”, line 908, in check\_validations  
len(input\_values) \> current\_validations[‘max\_length’]):  
TypeError: object of type ‘int’ has no len()

---

<div class="post-metadata">

**Author:** ![Sean](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/sean/32/543_2.png) [@Sean](https://community.pinecone.io/u/Sean)\
**Post date:** [May 18, 2023, 12:43am UTC](https://community.pinecone.io/t/upsert-fails-with-a-numeric-value-fields-python-lib-bug/1892/4 "2023-05-18T00:43:30Z")

</div>

Can you post your code? I think I was getting something like that when I first started experimenting with Pinecone (object has no len()) - it may have had to do with the tuple format.

---

<div class="post-metadata">

**Author:** ![kshrivastava](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/kshrivastava/32/551_2.png) [@kshrivastava](https://community.pinecone.io/u/kshrivastava)\
**Post date:** [May 22, 2023, 7:58pm UTC](https://community.pinecone.io/t/upsert-fails-with-a-numeric-value-fields-python-lib-bug/1892/5 "2023-05-22T19:58:56Z")

</div>

x[‘id’] was numeric…

```auto
    for i in tqdm(range(0, len(new_data), batch_size)):
        # find end of batch
        i_end = min(len(new_data), i + batch_size)
        meta_batch = new_data[i:i_end]
        # get ids
        ids_batch = [x['id'] for x in meta_batch]
        # get texts to encode
        texts = [x['text'] for x in meta_batch]
        # create embeddings (try-except added to avoid RateLimitError)
        try:
            res = openai.Embedding.create(input=texts, engine=embed_model)
        except:
            done = False
            while not done:
                sleep(5)
                try:
                    res = openai.Embedding.create(input=texts, engine=embed_model)
                    done = True
                except:
                    pass
        embeds = [record['embedding'] for record in res['data']]
        # cleanup metadata
        meta_batch = [{
            'text': x['text']
            , 'published': x['published']
        } for x in meta_batch]
        to_upsert = list(zip(ids_batch, embeds, meta_batch))
        # upsert to Pinecone
        index.upsert(vectors=to_upsert)

```

---

<div class="post-metadata">

**Author:** ![kshrivastava](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/kshrivastava/32/551_2.png) [@kshrivastava](https://community.pinecone.io/u/kshrivastava)\
**Post date:** [May 22, 2023, 7:59pm UTC](https://community.pinecone.io/t/upsert-fails-with-a-numeric-value-fields-python-lib-bug/1892/6 "2023-05-22T19:59:46Z")

</div>

Hi @Cory_Pinecone - Any insights?

---

<div class="post-metadata">

**Author:** ![Jasper](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/jasper/32/4514_2.png) [@Jasper](https://community.pinecone.io/u/Jasper)\
**Post date:** [May 23, 2023, 8:08am UTC](https://community.pinecone.io/t/upsert-fails-with-a-numeric-value-fields-python-lib-bug/1892/7 "2023-05-23T08:08:54Z")

</div>

Hi,

as per documentation, id should be a string 🙂

 ![image](https://us1.discourse-cdn.com/flex020/uploads/pinecone/original/1X/84eb88b24c26fe98683d08e96f639b6bdf32d880.png)

same in the Python lib documentation:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/pinecone/original/1X/f16e63c9d143a86aa82294690d9ba5f92a997343.png)

so if your IDs are an int, convert them to strings with str(id) or any other way 🙂

Hope this helps!

EDIT: Didn’t check the original post _facepalm_. Will leave the comment either way. Cheers.
