Revision 5351516d3e9b77fe4b0225c0b52883a718c4c0be authored by Andrew Brown on 12 November 2019, 14:40:39 UTC, committed by Taylor Otwell on 12 November 2019, 14:40:39 UTC
for attributes that are cast to any type of Object, the strict equivalency (`===`) will never return `true`, because even though the values may be equal, the Object there reference will be different.

this changes checks if the cast type is either `object` or `collection`, both with return Objects, and uses loose equivalency to compare them.

even though date casting also returns an Object, we don't need to handle that since it's handled in the previous conditional.

the test represents a scenario that occurs when using JSON fields in MySQL. MySQL returns the value with spaces between the elements, but `json_encode` returns a string **without** spaces between the elements.
1 parent de01f03
Raw File
DetectsConcurrencyErrors.php
<?php

namespace Illuminate\Database;

use Exception;
use Illuminate\Support\Str;
use PDOException;

trait DetectsConcurrencyErrors
{
    /**
     * Determine if the given exception was caused by a concurrency error such as a deadlock or serialization failure.
     *
     * @param  \Exception  $e
     * @return bool
     */
    protected function causedByConcurrencyError(Exception $e)
    {
        if ($e instanceof PDOException && $e->getCode() === '40001') {
            return true;
        }

        $message = $e->getMessage();

        return Str::contains($message, [
            'Deadlock found when trying to get lock',
            'deadlock detected',
            'The database file is locked',
            'database is locked',
            'database table is locked',
            'A table in the database is locked',
            'has been chosen as the deadlock victim',
            'Lock wait timeout exceeded; try restarting transaction',
            'WSREP detected deadlock/conflict and aborted the transaction. Try restarting the transaction',
        ]);
    }
}
back to top