Laravel eloquent returning SQLSTATE[HY000]: General error: 1815 Internal error: JSON wrapper: unexpected type after upgrading Aurora mysql
We had a query (select * from users where id IN ()) that due to an Amazon Aurora bug was causing a restart of the DB instance so Amazon support suggested an upgrade from Aurora MySQL version 3.02.2 with MySQL 8.0.23 to Aurora version 3.03.1 with MySQL 8.0.26.
Once the upgrade was done the restart issue disappeared but the query is still causing an error on the endpoint:
Illuminate\Database\QueryException · SQLSTATE[HY000]: General error: 1815 Internal error: JSON wrapper: unexpected type (SQL: select * from `users` where `users`.`id` in (<ids-of-the-users>) and `users`.`deleted_at` is null)
Same error on another endpoint for this query:
Illuminate\Database\QueryException · SQLSTATE[HY000]: General error: 1815 Internal error: JSON wrapper: unexpected type (SQL: select * from `users` where `stripe_customer_ref` = cus_test and `users`.`deleted_at` is null)
I tried to run the same queries directly on the database and I didn't get any errors so I suppose it's related to Laravel Eloquent.
This error is related to the JSON wrapper in Laravel Eloquent. To resolve this issue, you can try the following steps:
Clear the Laravel cache by running the following command in your terminal:
php artisan cache:clear
If the issue persists, try updating your Laravel framework to the latest version by running the following command:
composer update laravel/framework
If updating Laravel doesn't solve the problem, you can try modifying the affected queries to explicitly cast the JSON columns. For example, if the users table has a JSON column named data, you can modify the query like this:
$users = User::where('id', $ids)
->whereNull('deleted_at')
->selectRaw('CAST(data AS CHAR) AS data')
->get();
If none of the above steps work, you can try downgrading the Aurora MySQL version to the previous version that was working fine. This can be done through the Amazon RDS console.
If the issue still persists, it would be helpful to provide more details about your Laravel version, database schema, and the specific code where the error occurs.
hey @laryai unfortunately none of the above helped and downgrade to the old version of the database is not viable.
We currently have laravel with version 8.73.2.