speedtest-tracker icon indicating copy to clipboard operation
speedtest-tracker copied to clipboard

Error on migrate

Open garanda21 opened this issue 6 months ago • 3 comments

Describe the bug Receive an error on my notifications There was an issue migrating the data!

To Reproduce Steps to reproduce the behavior:

  1. Go to 'Result'
  2. Click on 'Migrate'
  3. See error

Expected behavior A clear and concise description of what you expected to happen.

Environment (please complete the following information):

  • OS: Synology Docker
  • Architecture: [e.g. arm64, amd64]
  • Browser Safari
  • Version 0.17.2

Screenshots If applicable, add screenshots to help explain your problem.

Logs

production.ERROR: Error: Object of class stdClass could not be converted to string in /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:723
08:39:33
Stack trace:
08:39:33
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php(723): PDOStatement->bindValue()
08:39:33
#1 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php(583): Illuminate\Database\Connection->bindValues()
08:39:33
#2 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php(816): Illuminate\Database\Connection->Illuminate\Database\{closure}()
08:39:33
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php(783): Illuminate\Database\Connection->runQueryCallback()
08:39:33
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php(576): Illuminate\Database\Connection->run()
08:39:33
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php(540): Illuminate\Database\Connection->statement()
08:39:33
#6 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(3336): Illuminate\Database\Connection->insert()
08:39:33
#7 /var/www/html/app/Actions/MigrateBadJsonResults.php(81): Illuminate\Database\Query\Builder->insert()
08:39:33
#8 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(174): App\Actions\MigrateBadJsonResults->App\Actions\{closure}()
08:39:33
#9 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(116): Illuminate\Database\Query\Builder->orderedChunkById()
08:39:33
#10 /var/www/html/app/Actions/MigrateBadJsonResults.php(62): Illuminate\Database\Query\Builder->chunkById()
08:39:33
#11 [internal function]: App\Actions\MigrateBadJsonResults->handle()
08:39:33
#12 /var/www/html/vendor/lorisleiva/laravel-actions/src/Concerns/DecorateActions.php(39): call_user_func_array()
08:39:33
#13 /var/www/html/vendor/lorisleiva/laravel-actions/src/Decorators/JobDecorator.php(61): Lorisleiva\Actions\Decorators\JobDecorator->callMethod()
08:39:33
#14 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Lorisleiva\Actions\Decorators\JobDecorator->handle()
08:39:33
#15 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
08:39:33
#16 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
08:39:33
#17 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\Container\BoundMethod::callBoundMethod()
08:39:33
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\Container\BoundMethod::call()
08:39:33
#19 /var/www/html/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(128): Illuminate\Container\Container->call()
08:39:33
#20 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}()
08:39:33
#21 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
08:39:33
#22 /var/www/html/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(132): Illuminate\Pipeline\Pipeline->then()
08:39:33
#23 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(123): Illuminate\Bus\Dispatcher->dispatchNow()
08:39:33
#24 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}()
08:39:33
#25 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
08:39:33
#26 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(122): Illuminate\Pipeline\Pipeline->then()
08:39:33
#27 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(70): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware()
08:39:33
#28 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(102): Illuminate\Queue\CallQueuedHandler->call()
08:39:33
#29 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(439): Illuminate\Queue\Jobs\Job->fire()
08:39:33
#30 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(389): Illuminate\Queue\Worker->process()
08:39:33
#31 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(176): Illuminate\Queue\Worker->runJob()
08:39:33
#32 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(137): Illuminate\Queue\Worker->daemon()
08:39:33
#33 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(120): Illuminate\Queue\Console\WorkCommand->runWorker()
08:39:33
#34 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Queue\Console\WorkCommand->handle()
08:39:33
#35 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
08:39:33
#36 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
08:39:33
#37 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\Container\BoundMethod::callBoundMethod()
08:39:33
#38 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\Container\BoundMethod::call()
08:39:33
#39 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(211): Illuminate\Container\Container->call()
08:39:33
#40 /var/www/html/vendor/symfony/console/Command/Command.php(326): Illuminate\Console\Command->execute()
08:39:33
#41 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(180): Symfony\Component\Console\Command\Command->run()
08:39:33
#42 /var/www/html/vendor/symfony/console/Application.php(1096): Illuminate\Console\Command->run()
08:39:33
#43 /var/www/html/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
08:39:33
#44 /var/www/html/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun()
08:39:33
#45 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(201): Symfony\Component\Console\Application->run()
08:39:33
#46 /var/www/html/artisan(35): Illuminate\Foundation\Console\Kernel->handle()
08:39:33
#47 {main}

Additional context Add any other context about the problem here.

Edited by @alexjustesen to help me read the logs.

Edit 2: Added zip file with database before and after migration in case you need it. Database before and after.zip

garanda21 avatar Feb 23 '24 07:02 garanda21

Added ZIP file with databases.

garanda21 avatar Feb 24 '24 09:02 garanda21

@alexjustesen guessing this relates to the issue I faced. https://github.com/alexjustesen/speedtest-tracker/issues/1179#issuecomment-1960383621

The root cause for this issue was the JSON of the first 764 were the backslashes were missing and a second line was saved in the JSON string.

Did not setup a correct development environment so I provide a the change to MigrateBadJsonResults.php here. First it uses "use Illuminate\Support\Str;". The second changes start at line 64 in the foreach statement.

/**

  • Some old results might include two lines (one is empty) */ if (Str::contains($result->data, PHP_EOL)) { //Replace empty line $json_string = Str::replace(PHP_EOL, '', $result->data); //Encode String to JSON which also provides backslashes $json = json_encode($json_string); } else { //Leave JSON as it is $json = $result->data; }

//Use JSON $record = [ 'service' => 'ookla', 'ping' => $result->ping, 'download' => $result->download, 'upload' => $result->upload, 'comments' => $result->comments, 'data' => json_decode($json, true),

sschneider avatar Feb 25 '24 02:02 sschneider

I can confirm that @sschneider suggestions works, after add the "fix" code on the file at line 64:

use Illuminate\Support\Str;

if (Str::contains($result->data, PHP_EOL)) 
{
      //Replace empty line
      $json_string = Str::replace(PHP_EOL, '', $result->data);
      //Encode String to JSON which also provides backslashes
      $json = json_encode($json_string);
} 
else 
{
      //Leave JSON as it is
      $json = $result->data;
}
                
$record = [
    'service' => 'ookla',
    'ping' => $result->ping,
    'download' => $result->download,
    'upload' => $result->upload,
    'comments' => $result->comments,
    'data' => json_decode($json,true)
...

I get the success message: image

And same count * on both tables!

garanda21 avatar Feb 25 '24 20:02 garanda21