l5-repository icon indicating copy to clipboard operation
l5-repository copied to clipboard

"Serialization of 'Illuminate\Http\UploadedFile' is not allowed"

Open netopvh opened this issue 7 years ago • 11 comments

I Need help to solve this error

Exception Serialization of 'Illuminate\Http\UploadedFile' is not allowed

vendor\prettus\l5-repository\src\Prettus\Repository\Traits\CacheableRepository.php

  • Serialize single criterion with customized serialization of Closures. *
    • @param \Prettus\Repository\Contracts\CriteriaInterface $criterion

    • @return \Prettus\Repository\Contracts\CriteriaInterface|array

    • @throws \Exception */ protected function serializeCriterion($criterion) { try { serialize($criterion);

       return $criterion;
      

      } catch (Exception $e) { // We want to take care of the closure serialization errors, // other than that we will simply re-throw the exception. if ($e->getMessage() !== "Serialization of 'Closure' is not allowed") { throw $e; }

       $r = new ReflectionObject($criterion);
      
       return [
           'hash' => md5((string) $r),
           'properties' => $r->getProperties(),
      

netopvh avatar Apr 11 '17 15:04 netopvh

I do get the same error. I had to disable caching for now. I hope I get around to take a closer look at it in the next few days and make a pull request if i find something.

rhwilr avatar Apr 12 '17 08:04 rhwilr

I tried to verify why this was happening and could not identify anything.

I'm waiting for correction.

netopvh avatar Apr 12 '17 12:04 netopvh

same issue

sergiybutenko avatar Jun 19 '17 17:06 sergiybutenko

bump

jjag3r avatar Nov 07 '17 13:11 jjag3r

Same issue. Someone found a solution?

zepaduajr avatar Nov 08 '17 11:11 zepaduajr

@zepaduajr Can you paste your code, and explain where the error ocurred?

eullercdr avatar Nov 08 '17 12:11 eullercdr

@eullercdr i've sent a request with uploaded file.

When i do any querys in repository (using CacheableRepository), i receive this error:

(1/1) Exception
Serialization of 'Illuminate\Http\UploadedFile' is not allowed
--
in CacheableRepository.php (line 161)

This error occurs when request is serialized: (inside CacheableRepository.php)

public function getCacheKey($method, $args = null)
    {

        $request = app('Illuminate\Http\Request');
--->    $args = serialize($args); <---
        $criteria = $this->serializeCriteria();
        $key = sprintf('%s@%s-%s', get_called_class(), $method, md5($args . $criteria . $request->fullUrl()));

        CacheKeys::putKey(get_called_class(), $key);

        return $key;

    }

In my request:

Request $request;
$request->files->parameters['blb_file'] (UploadedFile)

zepaduajr avatar Nov 08 '17 17:11 zepaduajr

My solution was to create a "Disable Caching" middleware and apply it to my route.

config(['repository.cache.enabled' => false]);

twcarefoot avatar Dec 20 '17 19:12 twcarefoot

i add "skipCache=true" in files upload routes

pedroufv avatar Feb 12 '19 18:02 pedroufv

my solution is modify serializeCriteria method in CacheableRepository.php just use try cache to ignore the error

        try {
            return serialize($this->getCriteria());
        } catch (Exception $e) {
            return serialize($this->getCriteria()->map(function ($criterion) {
                /** add here */
                try {
                    return $this->serializeCriterion($criterion);
                } catch (Exception $e) {
                    Log::warning($e->getMessage());
                }
            }));
        }

tsaiyihua avatar Mar 15 '19 08:03 tsaiyihua

The same issue, Plz fix it!

tranvanthuc avatar Dec 09 '19 15:12 tranvanthuc