You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue with the typesense driver, a collection named "collections" i.e. for a store system. Will cause an unhandled exception to be thrown.
in the getOrCreateCollectionFromModel Method from the TypesenseEngine it will try to check if the collection exists by calling this piece of code $this->typesense->getCollections()->{$collectionName};
The Problem is that the ->getCollections has a property called collections, this is accessible trough the __get method so it will return as an empty array.
Here is the Code in the TypesenseEngine with some Comments made by me to show the values and to explain what is going on.
Exception caused.
Call to a member function retrieve() on array
The issue is resolved when using another name other than collections. I am creating this issue to bring it to the attention of the developers, and most importantly, save some people some time when encountering this issue.
Steps To Reproduce
Create a new laravel project, install scout and create a model called Collection.
The text was updated successfully, but these errors were encountered:
The issue is in how the magic getter method (__get) works in Typesense's PHP Client library. Here's what's happening:
When the Collections class receives a request for a property (e.g., $collections->someCollection), the __get method first checks if a property with that name exists in the object instance
If a property named collections exists (which it does, as it's a property of the class), it returns that directly
This means when trying to access a collection named "collections" ($collections->collections), instead of creating a new Collection instance, it returns the internal $collections array
As a result, when Typesense Scout engine tries to call retrieve() on what it expects to be a Collection object, it fails because it got an empty array instead
This explains why the error only occurs specifically with the collection name "collections" and works fine with any other name. This is better explained in the PR I posted for the fix at the main Typesense PHP Client Repo
Scout Version
10.11.9
Scout Driver
Typesense
Laravel Version
11.9
PHP Version
8.4.1
Database Driver & Version
No response
SDK Version
4.9
Meilisearch CLI Version
No response
Description
Issue with the typesense driver, a collection named "collections" i.e. for a store system. Will cause an unhandled exception to be thrown.
in the getOrCreateCollectionFromModel Method from the TypesenseEngine it will try to check if the collection exists by calling this piece of code
$this->typesense->getCollections()->{$collectionName};
The Problem is that the ->getCollections has a property called collections, this is accessible trough the __get method so it will return as an empty array.
Here is the Code in the TypesenseEngine with some Comments made by me to show the values and to explain what is going on.
Exception caused.
The issue is resolved when using another name other than collections. I am creating this issue to bring it to the attention of the developers, and most importantly, save some people some time when encountering this issue.
Steps To Reproduce
Create a new laravel project, install scout and create a model called Collection.
The text was updated successfully, but these errors were encountered: