#community-help

Bug in Typesense Collection Naming with '#'

TLDR Gabriel identified a bug with using '#' in a Typesense collection name. The issue occurs with collection retrieval in the JS library, even when '#' is URL-encoded. Jason and Adarsh recognized the problem and Gabriel created a Github issue for it.

Powered by Struct AI
Mar 10, 2022 (20 months ago)
Gabriel
Photo of md5-0a5e04bd1893bc2c14da1cf700f1aed1
Gabriel
07:53 PM
Something interesting I found and I think it's a bug.

So if I create a collection with a # in the name.

I can create the collection using the JS library i.e. "collection_name#region"

The collection list will return that a collection with name "collection_name#region" exists.

But when I call to retrieve the collection, then the message is "Not found"

I tried the same with curl and it seems the same applies. When I tried using curl to delete the collection it seems that the returned message that the "#" is dropped as it returned a message of "No collection with name: "collection_name" "

The curl works if I encode the # to %23
so GET to /collections/collection_name%23region return a collection.

But this doesn't work in the JS library.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:49 PM
Gabriel Like you mentioned, you'd essentially need to URL encode any special characters before sending it to Typesense, either via CURL or via the JS client
08:49
Jason
08:49 PM
> But this doesn't work in the JS library.
Could you share the JS snippet you used for this?
Gabriel
Photo of md5-0a5e04bd1893bc2c14da1cf700f1aed1
Gabriel
09:39 PM
step 1)
create collection with JS lib.

let schema = {
'name': 'companies#region',
'fields': [
{
'name': 'company_name',
'type': 'string',
'facet': false
},
{
'name': 'date',
'type': 'int32',
'facet': false
},
{
'name': 'country',
'type': 'string',
'facet': true
}
],
'default_sorting_field': 'date'
}

client.collections().create(schema)

step 2)
check it exists
clients.collections().retrieve()

will return that it exists.

step 3)
client.collections('companies#region').retrieve()

returns not found.

step 4)
client.collections('companies%23region').retrieve()

also returns not found.
Mar 11, 2022 (20 months ago)
Adarsh
Photo of md5-df15c9310a80198b9380cc0fa3d991f1
Adarsh
10:06 AM
Gabriel - that is expected behavior in browser because according to spec (RFC 3986) # is URL Fragment and is not sent to backend, browser will strip anything that comes after # before making the request to backend.. if you want to have # then as you discovered, you need to encode it.. (it may be a bad practice, since there are lot of http client libraries which misbehaves)
Gabriel
Photo of md5-0a5e04bd1893bc2c14da1cf700f1aed1
Gabriel
10:13 AM
Adarsh yeah I understand.

But I think this behavior is a bug in a sense that
you can create the a collection with a name with a # without encoding it.

But then in JS lib you can't retrieve the collection, even if you encode the # to %23.

And JS lib is not necessary running in a browser, it might be a lambda function or a nodejs.
Adarsh
Photo of md5-df15c9310a80198b9380cc0fa3d991f1
Adarsh
10:38 AM
Ah I see 👍
Gabriel
Photo of md5-0a5e04bd1893bc2c14da1cf700f1aed1
Gabriel
12:21 PM
Jason I have created a bug with suggestions on how this could be handled.
https://github.com/typesense/typesense/issues/548

It's a minor thing, but it was just a bit annoying, that I created a collection and it worked, but then had to go through logs to find out why it was failing when trying to insert documents. 🙂
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
07:42 PM
Thanks Gabriel. Will take a closer look