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

[BUG] The attribute [routing] either does not exist or was not retrieved for model [App\Models\Track]. #247

Open
defser opened this issue Apr 21, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@defser
Copy link

defser commented Apr 21, 2023

Describe the bug
MissingAttributeException error appears when running php artisan scout:import

final class Track extends Model
{
use HasFactory;
use Searchable;
use SoftDeletes;
}

Importing [App\Models\Track]
Create write index
2/5 [⚬⚬⚬⚬⚬⚬⚬⚬⚬⚬⚬➤⚬⚬⚬⚬⚬⚬⚬⚬⚬⚬⚬⚬⚬⚬⚬⚬] 40%

Illuminate\Database\Eloquent\MissingAttributeException

The attribute [routing] either does not exist or was not retrieved for model [App\Models\Track].

at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:472

To Reproduce
Steps to reproduce the behavior:

  1. Create a model with
    final class Track extends Model
    {
    use HasFactory;
    use Searchable;
    use SoftDeletes;
    }
  2. Run a command
    php artisan scout:import
  3. See error
    The attribute [routing] either does not exist or was not retrieved for model [App\Models\Track].

vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:452
Illuminate\Database\Eloquent\Model::throwMissingAttributeExceptionIfApplicable("routing")

2 vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2227
Illuminate\Database\Eloquent\Model::getAttribute("routing")

3 vendor/matchish/laravel-scout-elasticsearch/src/ElasticSearch/Params/Bulk.php:47
Illuminate\Database\Eloquent\Model::__get("routing")

Expected behavior
model is synced to index

Additional context
When adding
public null|string $routing = null;
to the model the problem is solved but why is this necessary? Also the documentation does not say anything about it.

change possible causing this issue: https://github.com/matchish/laravel-scout-elasticsearch/pull/91/files

Version
laravel/framework: v10.8.0
laravel/scout: v10.1.1
matchish/laravel-scout-elasticsearch: v7.2.1

@defser defser added the bug Something isn't working label Apr 21, 2023
@hkulekci
Copy link
Contributor

Do you have any field as routing in the model? routing is a reserved field in Elasticsearch. Could it be related to that?

@hkulekci
Copy link
Contributor

Ahh, sorry, I saw the PR you shared already now.

@matchish
Copy link
Owner

I'll try to create a red test next weekend, but I'm pretty sure that you're right and it's because of
https://github.com/matchish/laravel-scout-elasticsearch/pull/91/files and some Laravel magic

@defser
Copy link
Author

defser commented Apr 24, 2023

@matchish I now see that one of our configuration causes this issue to happen:

final class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
Model::preventLazyLoading(!$this->app->isProduction());
Model::preventAccessingMissingAttributes();
Model::preventSilentlyDiscardingAttributes();
}
}

We use Model::preventAccessingMissingAttributes(); to prevent magical bugs in our application. This exception shows us that the package is trying to access a missing attrubute.

@matchish
Copy link
Owner

matchish commented Jun 6, 2023

@defser could you try last release? should work fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants