typesense / typesense

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Home Page:https://typesense.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Documents cannot be retrieved if 'id' field contains '/' character

DarakDuVal opened this issue · comments

Description

When documents are created with an id which contains the special char /, the document cannot be retrieved through its id but returns typesense.exceptions.ObjectNotFound: [Errno 404] Not Found

Support for / is required to accommodate RFC 8141

Steps to reproduce

this one works

schema = { 'name': 'foo', 'fields': [{'name': 'id', 'type': 'string'}]}
client.collections.create(schema)
document = {'id': 'good-id'}
client.collections['foo'].documents.create(document)
client.collections['foo'].documents['good-id'].retrieve()

and prints out {'id': 'good-id'}

this one does not

schema = { 'name': 'bar', 'fields': [{'name': 'id', 'type': 'string'}]}
client.collections.create(schema)
document = {'id': 'bad/id'}
client.collections['bar'].documents.create(document)
client.collections['bar'].documents['bad/id'].retrieve()

raises ObjectNotFound exception

Detailed stack trace

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.3.4\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
           ^^^^^^
  File "<input>", line 1, in <module>
  File "C:\Users\olive\PycharmProjects\mekong\venv\Lib\site-packages\typesense\document.py", line 14, in retrieve
    return self.api_call.get(self._endpoint_path())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olive\PycharmProjects\mekong\venv\Lib\site-packages\typesense\api_call.py", line 146, in get
    return self.make_request(session.get, endpoint, as_json,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\olive\PycharmProjects\mekong\venv\Lib\site-packages\typesense\api_call.py", line 116, in make_request
    raise ApiCall.get_exception(r.status_code)(r.status_code, error_message)
typesense.exceptions.ObjectNotFound: [Errno 404] Not Found

Expected Behavior

client.collections['bar'].documents['bad/id'].retrieve() should return the document

Actual Behavior

raises exception typesense.exceptions.ObjectNotFound: [Errno 404] Not Found

Metadata

Typesense Version: typesense 0.19.0 from PyPI

OS: Microsoft Windows [Version 10.0.22631.3155]

Could you try url encoding the ID before passing it into the library?

Agreed, this shows the expected behavior:

>>> client.collections['bar'].documents[urllib.parse.quote_plus('bad/id')].retrieve()
{'id': 'bad/id'}

Is there a chance to call this on every document ID passed? In case of "good" ID's it should not make a difference (to be tested).