dustin10 / VichUploaderBundle

A simple Symfony bundle to ease file uploads with ORM entities and ODM documents.
MIT License
1.83k stars 519 forks source link

File injection on load not working reliabely with lazy ghost objects #1439

Open wryk opened 5 months ago

wryk commented 5 months ago

Bug Report

Q A
BC Break yes
Bundle version 2.3.0
Symfony version 6.4.3
PHP version 8.2.13

Summary

inject_on_load option doesn't work as previously expected when doctrine use lazy ghost objects (since doctrine/orm 3.0.0 or below when enabling them).

According to https://github.com/doctrine/DoctrineBundle/issues/1651#issuecomment-1684297751 this might be an expected behavior of the new proxy internal (and might wontfix in doctrine) so this is why I address this issue here.

Current behavior

When accessing the file object on a uninitialized entity the file is not injected.

How to reproduce

Reproducible example : https://github.com/wryk/vich-uploader-issue-1439-lazy-ghost-inject-load

Expected behavior

Without lazy ghost objects the injection worked fine, I expect the inject_on_load to work without having to ensure the entity is not a proxy or is initialized.

If not practically fixable in the bundle this regression should be documented or maybe because of the reliability issue inject_on_load should be replaced/removed.