Open defser opened 1 year ago
Do you have any field as routing
in the model? routing
is a reserved field in Elasticsearch. Could it be related to that?
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
@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.
@defser could you try last release? should work fine
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:
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