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

Typesense Driver - Call to a member function retrieve() on array #896

Closed
Thiritin opened this issue Dec 13, 2024 · 3 comments
Closed

Typesense Driver - Call to a member function retrieve() on array #896

Thiritin opened this issue Dec 13, 2024 · 3 comments
Assignees

Comments

@Thiritin
Copy link

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.

image

Here is the Code in the TypesenseEngine with some Comments made by me to show the values and to explain what is going on.

image

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.

@tharropoulos
Copy link
Contributor

I'll investigate and get back to you

@tharropoulos
Copy link
Contributor

tharropoulos commented Dec 17, 2024

The issue is in how the magic getter method (__get) works in Typesense's PHP Client library. Here's what's happening:

  1. 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
  2. If a property named collections exists (which it does, as it's a property of the class), it returns that directly
  3. 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
  4. 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

@crynobone
Copy link
Member

Looks like this is an upstream issue. Closing this and please continue typesense/typesense-php#79

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

No branches or pull requests

3 participants