Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use other type than string for ObjectID #855

Open
Rickos99 opened this issue May 6, 2024 · 0 comments
Open

Use other type than string for ObjectID #855

Rickos99 opened this issue May 6, 2024 · 0 comments

Comments

@Rickos99
Copy link

Rickos99 commented May 6, 2024

  • Algolia Client Version: 6.16.0
  • Language Version: .NET 8.0

Description

I want to assign Id of type GUID to ObjectID without adding a second property.

Steps To Reproduce

  1. Create the following class

    public class A
    {
        [JsonProperty(PropertyName = "objectID")]
        public Guid Id { get; set; }
    
        public string Data {get; set}
    }
  2. Create instance of A

  3. Use Algolia.Search.Clients.SearchIndex.SaveObjectAsync(...) and save it to an index.

    This will result in

Algolia.Search.Exceptions.AlgoliaException: The ObjectID property or the JsonPropertyAttribute with name='objectID' must be a string
   at Algolia.Search.Utils.AlgoliaHelper.EnsureObjectID[T]()
   at Algolia.Search.Clients.SearchIndex.SaveObjectsAsync[T](IEnumerable`1 data, RequestOptions requestOptions, CancellationToken ct, Boolean autoGenerateObjectId)
   at Algolia.Search.Clients.SearchIndex.SaveObjectAsync[T](T data, RequestOptions requestOptions, CancellationToken ct, Boolean autoGenerateObjectId)
   ...

Solution

public class A
{
    public Guid Id { get; set; }

    public string ObjectID { get => Id.ToString(); }

    public string Data {get; set}
}

Proposal

This is where the exception is thrown. Would it make sense to allow other types such as GUID in the ObjectID property or is there a reason for it to be string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant