rest-api icon indicating copy to clipboard operation
rest-api copied to clipboard

Unable to write to metaData

Open davidbiga opened this issue 5 years ago • 8 comments

Hello,

I've built this project around Docker and have configured the right dependencies, project, but when I run a request to login, I keep getting an error exception thrown the MetaData class.

Here is the exact error:

<br />
<b>Fatal error</b>:  Uncaught Phalcon\Mvc\Model\Exception: Failed to store metaData to the cache adapter in /api/library/Traits/QueryTrait.php:139
Stack trace:
#0 [internal function]: Phalcon\Mvc\Model\MetaData-&gt;throwWriteException(true)
#1 [internal function]: Phalcon\Mvc\Model\MetaData-&gt;write('map-phalcon\\api...', Array)
#2 [internal function]: Phalcon\Mvc\Model\MetaData-&gt;initialize(Object(Phalcon\Api\Models\Users), NULL, NULL, NULL)
#3 [internal function]: Phalcon\Mvc\Model\MetaData-&gt;readColumnMapIndex(Object(Phalcon\Api\Models\Users), 1)
#4 [internal function]: Phalcon\Mvc\Model\MetaData-&gt;getReverseColumnMap(Object(Phalcon\Api\Models\Users))
#5 [internal function]: Phalcon\Mvc\Model\MetaData-&gt;hasAttribute(Object(Phalcon\Api\Models\Users), 'username')
#6 [internal function]: Phalcon\Mvc\Model\Query-&gt;_getQualified(Array)
#7 [internal function]: Phalcon\Mvc\Model\Query-&gt;_getExpression(Array, true)
#8 [internal function]: Phalcon\Mvc\Model\Query-&gt;_getExpression(Array, true)
#9 [internal function]: Phalcon\Mvc\Model\Query-&gt;_getEx in <b>/api/library/Traits/QueryTrait.php</b> on line <b>139</b><br />

I did make sure that memcached was installed and also running on my machine. Permissions seem to be correct on the folders as it is able to write logs within the storage directory.

Do you have any suggestions?

davidbiga avatar Aug 22 '20 15:08 davidbiga

@davidbiga Hi,Did you have any idea (or demostration) of pagination?

xaero7 avatar Aug 24 '20 09:08 xaero7

Hi @davidbiga, what is the version of Phalcon that you use ? @xaero7, you can find an example here : https://github.com/les-enovateurs/livre-phalcon/blob/master/Chapitre%2009%20-%20Bases%20de%20donn%C3%A9es%20-%20Les%20mod%C3%A8les%20Phalcon/2.17%20-%20Pagination%20des%20r%C3%A9sultats/www/app/controllers/BddController.php

jenovateurs avatar Aug 24 '20 09:08 jenovateurs

@xaero7 @jenovateurs this is not about pagination. This when when the API is preparing the sql query to execute and store the models MetaData into cache.

Phalcon Version: 4.0.5 Phalcon DevTools Version: 4.0.0 PHP Version: 7.4.9

davidbiga avatar Aug 24 '20 13:08 davidbiga

@davidbiga Did you try to comment memcached service and make a simple request to the database. Just to verify that the connection between the API and database works.

jenovateurs avatar Aug 24 '20 14:08 jenovateurs

@jenovateurs You're referring to commenting out:

$container->setShared(
            'modelsMetadata',
            function () {
                $backOptions = [
                    'servers'  => [
                        0 => [
                            'host'   => envValue('DATA_API_MEMCACHED_HOST', '127.0.0.1'),
                            'port'   => envValue('DATA_API_MEMCACHED_PORT', 11211),
                            'weight' => envValue('DATA_API_MEMCACHED_WEIGHT', 100),
                        ],
                    ],
                    'client'   => [
                        \Memcached::OPT_PREFIX_KEY => 'api-',
                    ],
                    'lifetime' => 3600,
                    'prefix'   => 'metadata-',
                ];

                $serializer = new SerializerFactory();
                $adapterFactor = new AdapterFactory($serializer);

                return new Libmemcached($adapterFactor, $backOptions);
            }
        );

inside ModelsMetadataProvider? Also per the Exception thrown, shouldn't a "can't connect to db" be thrown prior?

davidbiga avatar Aug 24 '20 14:08 davidbiga

@davidbiga yes can you comment this block of your code. Just to check if there isn't another error.

jenovateurs avatar Aug 24 '20 15:08 jenovateurs

@jenovateurs I disabled modelsMetadata, had to fix a DB connection issue and logged in request went through with a 200. After I re-enabled modelsMetadata, I was met with the same error message.

davidbiga avatar Aug 24 '20 15:08 davidbiga

@davidbiga I think it's a Phalcon issue and not a problem related to this rest-api project. Could you transfer/write this issue in the Phalcon project ? https://github.com/phalcon/cphalcon/issues I think you will get more answers to your problem.

jenovateurs avatar Aug 25 '20 12:08 jenovateurs