Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZF gets trapped in symfony entity error even after error is solved #65

Open
michalbundyra opened this issue Jan 10, 2020 · 2 comments
Open

Comments

@michalbundyra
Copy link
Member

We're building an API over a symfony2 app. The API invokes symofiny services which return symfony entities.

The thing is working ok, but after a runtime error in the symfony app, calls to API endpoints keep returning an entity annotation error even when the error is solved. After some days getting this error I think the message is actually not relevant, it was only a simple error in the entity

        {
          "file": "/var/www/my-api/public/index.php",
          "line": 38,
          "function": "run",
          "class": "Zend\\Mvc\\Application",
          "type": "->",
          "args": []
        }
      ],
      "type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
      "title": "Internal Server Error",
      "status": 500,
      "detail": "[Semantical Error] The annotation \"@Doctrine\\ORM\\Mapping\\Entity\" in class App\\UserBundle\\Entity\\Usuario does not exist, or could not be auto-loaded."
    }

To reproduce this issue you can force a runtime error in the symfony entity (in my case it was using $var->attr instead of $this->attr), maybe entity needs to be annotated to reproduce same environment.

This is my fetch nethod, the one which keeps returning the error:

    public function fetch($id)
    {
        $usuario =  $this->userServiceSymfony->getUser($this->doctrine, $id);

        // return $usuario->getArrayCopy();

        return array('id' => $usuario->getId(), 
                     'nombre' => $usuario->getNombre(), 
                     'apellidos' => $usuario->getApellidos(),
                     'fechanacimiento' => $usuario->getFechanacimiento(),
                     'telefono' => $usuario->getTelefono(),
                     'campaignid' => $usuario->getCampaignid(),
                     'email' => $usuario->getEmail(),
                     'lastlogin' => $usuario->getLastLogin(),
                     );
    }

Yesterday I was only able to recover from this error with a hard reset of a very previous commit, today, after some improvements I found the error again.


Originally posted by @nzurita at zfcampus/zf-apigility#60

@michalbundyra
Copy link
Member Author

So far we found out we can get around this using this in /public/index.php:

use \Doctrine\Common\Annotations\AnnotationReader;

AnnotationReader::addGlobalIgnoredName('App\UserBundle\Entity\Usuario');

We guess we'll need to add this for all entities that will be used, so anyway it would be nice that someone takes care of this issue (just to remember, there is no annotation error)

EDIT: actually this doesn't work, the problem persists


Originally posted by @nzurita at zfcampus/zf-apigility#60 (comment)

@michalbundyra
Copy link
Member Author

In case this is helpful to someone else, I came across this thread when I had a similar issue with annotations not being recognized. I found the problem to be that my AppKernel that was bootstrapped in the Apigility app was assuming a production environment (following this tutorial), so it was likely that my production cache was out of sync with my development cache. To resolve this, I made the AppKernel environment in Apigility match the environment of the existing Symfony2 app, and the error went away. I posted more detail about this in this thread.


Originally posted by @sgilberg at zfcampus/zf-apigility#60 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant