Skip to content

Doctrine lazy ghost object resulting in typing error when web profiler info is collected #52774

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

Closed
RobertMe opened this issue Nov 28, 2023 · 5 comments

Comments

@RobertMe
Copy link
Contributor

Symfony version(s) affected

6.4-RC2

Description

First off I wasn't sure whether to report this here or for the Doctrine Bundle, but as the error is triggered in Symfony code and I did read that @nicolas-grekas did some "lazy ghost voodoo" for the Doctrine Bundle I guess this is a better place to report it :)

Secondly I'm not sure what the fault is yet, nor how to properly reproduce. But what I do know is that doctrine.orm.enable_lazy_ghost_objects being enabled leads to a very strange error with the web profiler. And as I discovered this on the RC version it might be an issue with the RC? Which thus might be something which you'd want to fix before releasing the stable (although I guess it's a bit late / short before the release for that)

In certain scenario's (/on certain pages) the page will end with the following error:

Cannot assign Symfony\Component\VarDumper\Caster\CutStub to reference held by property SomeEntity::$someProperty of type SomeType

This is triggered by the $a[$k] = new CutStub($v); in the DataCollector. In this case $k would resemble a type hinted property (fails both with enum types as object types, at first I thought it might have been enum only) of some class (so in the example it is SomeEntitysomeProperty, for which I'm guessing the FQCN and property are separated by a NULL byte) to which it obviously is trying to assign a new CutStub which doesn't satisfy some "dubiously" inherited type constraint. But I do have absolutely no idea what is triggering this error. This as $a is an array, so it can't actually be typehinted (I've never heart of typehinted array keys/values before 😅), so it seemingly has to do with the "reference held by property"? But I haven't figured out how $a is created yet, so I also don't know whether it involves some &$obj->prop based assignment.

What I do know is that, at least for me, this error is triggered by a Security->isGranted() call where this (Doctrine) entity is used as $subject, and the entity is a (loaded / initialized) proxy (i.e.: a proxy instance has been created due to some other entity actually being loaded which references this entity, after which at some point I have this (now loaded) proxy instance and pass it to isGranted). Which I "discovered" based on the stacktrace (which shows it's eventually called by Symfony\Bundle\SecurityBundle\DataCollector\SecurityDataCollector::lateCollect()) and intensively trying to debug and understand what was going on in the VarDumper code showing one of my attribute names before failing giving the "hint" to disable the isGranted call, and then it works).

How to reproduce

As described above I haven't (tried to) set up a proper reproducer yet. But after writing everything down I do believe it might be as simple as:

  1. Making sure the (new) doctrine.orm.enable_lazy_ghost_objects setting is enabled (for which not enabling it will be deprecated)
  2. Having the WebProfiler enabled
  3. Having a Doctrine entity with object (/ enum) typed properties
  4. Getting a proxy to this entity (i.e.: creating the proxy by loading an entity referencing it, or possibly by calling getReference())
  5. Possibly making sure the proxy is loaded / initialized? (it is in my case, not sure if it also fails when it isn't initialized yet)
  6. calling ->isGranted() with this entity as subject (in my case it's called on the Security helper class/service, but I guess using the AccessManager directly would result in the same error)

Possible Solution

No response

Additional Context

Symfony: ^6.4 RC (so RC2 / RC1 depending on which packages have an RC2)
DoctrineBundle: 2.11.1
PHP: 8.1.2

@stof
Copy link
Member

stof commented Nov 28, 2023

Duplicates #49091

PHP 8.1.2 is affected by a bug which is known to impact VarDumper. This bug has been fixed in PHP 8.1.8.

@stof stof closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2023
@RobertMe
Copy link
Contributor Author

Whoops, thanks @stof, not sure how I didn't find that ticket.

@stof
Copy link
Member

stof commented Nov 28, 2023

Note that I literally found it by putting Cannot assign Symfony\Component\VarDumper\Caster\CutStub to reference held by property in the issue search box.

@RobertMe
Copy link
Contributor Author

I did as well, but in the issue search / filter box, and apparently didn't notice the "1 Closed". So lesson learned, use the "global" search :)

Anyway, sorry for the report. Luckily it was easily "solved" on your end and it only costed me some time to write the report, instead of you having invested a lot of time to then still find out it's a ("solved") duplicate.

@stof
Copy link
Member

stof commented Nov 28, 2023

Well, I did not spent a lot of time as I recognized the error message directly so I knew from the start it was a duplicate. But thanks anyway.

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

No branches or pull requests

4 participants