Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Strange issue when $em is cleared in kernel.terminate #263

Copy link
Copy link
Closed
@zmitic

Description

@zmitic
Issue body actions

For a form page like this (I removed excess code for simplicity):

class MovieType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder->add('director', EntityType::class, [
            'class' => MovieDirector::class,
           // query builder etc
        ]);

        $builder->add('name');
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => Movie::class,
        ]);
    }
}

and this subscriber:

public function onKernelTerminate(PostResponseEvent $event)
{
    $this->em->clear();
}

with usual controller code:

public function editMovieAction(Movie $movie, Request $request): Response
{
    $em = $this->getDoctrine()->getManager();
    $form = $this->createForm(MovieType::class, $movie);

    $form->handleRequest($request);
    if ($form->isSubmitted() && $form->isValid()) {
        $em->flush();

        return $this->redirectToRoute('movie_detailed', ['id' => $movie->getId()]);
    }

    return $this->render('movies/form.html.twig', [
        'form' => $form->createView(),
        'all_movies' => $$this->getDoctrine()->getRepository(Movie::class)->findAll(),
    ]);
}

I get this error on second form submission (because form was invalid):

image

If I remove $em->clear() from kernel.terminate event, it doesn't happen but since $em is shared, other user sees the changes.

The reason I put that code is so identity map doesn't get filled up quickly since it is shared among users. Also, it allows me to work on entities directly without the need for creating DTO classes.

Same problem happens if I put it in all other events like kernel.request, kernel.controller... doesn't change anything.

Any idea?


Btw, I really like this package. I get around 10ms on php7.1 compared to 170ms with server:run.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.