Unable to write to metaData
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->throwWriteException(true)
#1 [internal function]: Phalcon\Mvc\Model\MetaData->write('map-phalcon\\api...', Array)
#2 [internal function]: Phalcon\Mvc\Model\MetaData->initialize(Object(Phalcon\Api\Models\Users), NULL, NULL, NULL)
#3 [internal function]: Phalcon\Mvc\Model\MetaData->readColumnMapIndex(Object(Phalcon\Api\Models\Users), 1)
#4 [internal function]: Phalcon\Mvc\Model\MetaData->getReverseColumnMap(Object(Phalcon\Api\Models\Users))
#5 [internal function]: Phalcon\Mvc\Model\MetaData->hasAttribute(Object(Phalcon\Api\Models\Users), 'username')
#6 [internal function]: Phalcon\Mvc\Model\Query->_getQualified(Array)
#7 [internal function]: Phalcon\Mvc\Model\Query->_getExpression(Array, true)
#8 [internal function]: Phalcon\Mvc\Model\Query->_getExpression(Array, true)
#9 [internal function]: Phalcon\Mvc\Model\Query->_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 Hi,Did you have any idea (or demostration) of pagination?
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
@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 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 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 yes can you comment this block of your code. Just to check if there isn't another error.
@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 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.