#community-help

Troubleshooting Typesense Document Update Error

TLDR Mehdi had an issue with updating Typesense documents which returned a '404 Not Found' error. Kishore Nallan after several debugging steps, discovered Mehdi was using an outdated Typesense version. The issue was resolved after upgrading Typesense.

Powered by Struct AI
+11
raised_hands1
32
26mo
Solved
Join the chat
Jul 28, 2021 (26 months ago)
Mehdi
Photo of md5-a3ecae8c75dfccecfa4e0116c9241a34
Mehdi
09:25 AM
Hey

I'm working on changes streams, which is reflecting data changes in MongoDB documents to Typesense collections

This is my code:

print(_id)
document = insert_change['updateDescription']['updatedFields']
print(document)
print(CLIENT.collections[TYPESENSE_COLLECTION].documents[_id].retrieve())
r = CLIENT.collections[TYPESENSE_COLLECTION].documents[_id].update(document)
print(r)

This is the response
5fae9573f56f4d5f91b8c02d
{'name': 'Le Zii'}
{'_cls': 'Model', 'address': '', 'admin_uuid': {'$uuid': 'f25b39ef25ba11ebb464bc5ff4bfaa62'}, 'categories': ['Fast Food et Pizzerias'], 'city': 'Texas', 'coordinates': {'coordinates': [30.1769166, 40.8368248], 'type': 'Point'}, 'country': 'France', 'created_at': '2020-11-13 14:17:15.782000', 'created_by_uuid': {'$uuid': 'f25b39ef25ba11ebb464bc5ff4bfaa62'}, 'cuisines': [], 'description': 'Best burger in town :)', 'email': '', 'facebook_url': '', 'gallery': [], 'google_maps_url': '', 'has_ordering_service': False, 'has_qr_code': False, 'hours': {'Dimanche': ['0'], 'Jeudi': ['12:00', '23:00'], 'Lundi': ['12:00', '23:00'], 'Mardi': ['12:00', '23:00'], 'Mercredi': ['12:00', '23:00'], 'Samedi': ['12:00', '23:00'], 'Vendredi': ['12:00', '23:00']}, 'id': '5fae9573f56f4d5f91b8c02d', 'instagram_url': '', 'is_activated_by_admin': True, 'is_public': False, 'logo': '', 'menu_items': [], 'more_services': ['Livraison', 'Tickets resto'], 'name': 'Le Z', 'operator': {'_cls': 'BaseModel', '_ref': {'$id': {'$oid': '5fae9573f56f4d5f91b8c02e'}, '$ref': 'base_model'}}, 'price': 3, 'price_range': '$$$', 'private_phone_numbers': [], 'profile_picture': '', 'public_phone_numbers': ['0000'], 'rating': 0, 'reviews_count': 0, 'specialties': ['Burger'], 'state': 'Ariana', 'tagline': '', 'trends': 'Eat Out', 'updated_at': '2021-07-12 14:57:47.548000', 'uuid': 'f25b39ec-25ba-11eb-b464-bc5ff4bfaa62', 'website_url': '', 'zip_code': '0000'}


As you can see, the document exists in my Typesense collection, but when I call update() it returns [Errno 404] Not Found . Any idea why this is happening?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:43 AM
👋 Just to be sure nothing else is going wrong, can you just try this separately:

print(CLIENT.collections[TYPESENSE_COLLECTION].documents['5fae9573f56f4d5f91b8c02d'].retrieve())

# Try inserting an empty document to see what error message you are getting now
print(CLIENT.collections[TYPESENSE_COLLECTION].documents['5fae9573f56f4d5f91b8c02d'].update({}))
09:44
Kishore Nallan
09:44 AM
If you notice, I'm directly using the ID 5fae9573f56f4d5f91b8c02d in the client code snippet above for both retrieve and update.
Mehdi
Photo of md5-a3ecae8c75dfccecfa4e0116c9241a34
Mehdi
09:46 AM
Thank you for answering
It's the same result
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:47 AM
It can print the document, but returns 404 error code during update?
Mehdi
Photo of md5-a3ecae8c75dfccecfa4e0116c9241a34
Mehdi
09:48 AM
Yes
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:48 AM
Can you also please try with this CURL request directly?

curl "<COLLECTION>/documents/5fae9573f56f4d5f91b8c02d" -X PATCH \
        -H "Content-Type: application/json" \
        -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
        -d '{}'
09:49
Kishore Nallan
09:49 AM
And please post the exact response received on the terminal.
Mehdi
Photo of md5-a3ecae8c75dfccecfa4e0116c9241a34
Mehdi
09:50 AM
It returns

{ "message": "Not Found"}
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:50 AM
🤔 What version of Typesense are you on?
Mehdi
Photo of md5-a3ecae8c75dfccecfa4e0116c9241a34
Mehdi
09:53 AM
How can I check that?
09:53
Mehdi
09:53 AM
It was installed by one our sys admins so I'm not sure
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:53 AM
I think you might be hitting the wrong collection. Because if the document is not found, the error message will be like this:

{"message": "Could not find a document with id: 1a"}
09:54
Kishore Nallan
09:54 AM
I just checked this locally as well to confirm. Only when the collection itself is not found, do you get:

{"message": "Not Found"}
Mehdi
Photo of md5-a3ecae8c75dfccecfa4e0116c9241a34
Mehdi
09:59 AM
This is weird because when I call retrieve() it returns the document 😕
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:59 AM
Just to confirm: is this both on the same stand-alone script? Can you please hardcode the TYPESENSE_COLLECTION variable name as well?
Mehdi
Photo of md5-a3ecae8c75dfccecfa4e0116c9241a34
Mehdi
10:02 AM
Yes
10:02
Mehdi
10:02 AM
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:05 AM
I just checked the server code, and the validation for collection existing is the same for both the update and retrieve end-points. So weird... Looking.
10:08
Kishore Nallan
10:08 AM
Are you able to search on the collection?
10:09
Kishore Nallan
10:09 AM
Typesense version can be accessed by hitting /debug
Jul 29, 2021 (26 months ago)
Mehdi
Photo of md5-a3ecae8c75dfccecfa4e0116c9241a34
Mehdi
06:39 AM
I'm sorry for the delay
06:40
Mehdi
06:40 AM
Yes search works fine
06:40
Mehdi
06:40 AM
06:42
Mehdi
06:42 AM
/debug returns {
"state": 1,
"version": "0.15.0"
}
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
06:44 AM
That's a really old version of Typesense. Latest stable is 0.21. Can you please ask your sys admins to upgrade? It will be very difficult for me to debug an year old version, unfortunately.
Mehdi
Photo of md5-a3ecae8c75dfccecfa4e0116c9241a34
Mehdi
06:56 AM
I took the liberty of updating it
Now updating documents works fine !
06:56
Mehdi
06:56 AM
I don't know why he would install an old version
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
06:57 AM
It's possible that 0.15 doesn't even have that update endpoint.
06:57
Kishore Nallan
06:57 AM
So the 404 error was actually, endpoint not found!
06:58
Kishore Nallan
06:58 AM
Also, it's cool that you were able to upgrade 6 versions just like that -- we've certainly worked hard to preserve backward compatibility!
raised_hands1
Mehdi
Photo of md5-a3ecae8c75dfccecfa4e0116c9241a34
Mehdi
07:23 AM
Thank you for your help 🙌
+11