Skip to content

Proxy object not fully loaded and tries to write unset values back to database #54521

@craigh

Description

@craigh

Symfony version(s) affected

6.4.*

Description

enable_lazy_ghost_objects is causing an issue where

  1. when loading an entity with and chain of relations marked EAGER, entities down the chain are not fully loaded.
  2. Then on EntityManager->flush() the unset values are attempted to be written to the database

How to reproduce

Here is a reproducer: https://github.com/craigh/bug-reproducer-1

If you run the reproducer, it better explains the problem than I can do here.

also for reference: https://stackoverflow.com/questions/78267848/proxy-object-tries-to-write-unset-values-to-database?noredirect=1#comment138011312_78267848


I have an EntityA that has EAGER loaded ManyToOne relation to EntityB. EntityB also has EAGER loaded ManyToOne relation to EntityC.

I have a simple controller to edit EntityA. It loads EntityA in the action arg, e.g. public function edit(EntityA $a): Response {}.

In the controller I make a few changes to $a and then flush the entity manager. On flush I get the error

SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘first_name’ cannot be null

It appears that the proxy is not loading the relations and then on flush, attempting to write the non-loaded values back on the entity.

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy