- Notifications
You must be signed in to change notification settings - Fork9.6k
Description
Symfony version(s) affected
7.2
Description
I have the following message (event) where$order
is a simple DTO and$customer
is a Doctrine entity:
#[AsMessage('async')]finalclass CapturePayPalOrderCompleted{publicfunction__construct(publicreadonlyOrder$order,publicreadonlyCustomer$customer, ) { }}
In my listener I can use any "direct" property ofCustomer
without problems, even when event is dispatched asynchronously.I can't, however, access any related entity property (apart from theid
) when dispatched asynchronously:
publicfunction__invoke(CapturePayPalOrderCompleted$event):void{// Works, values are present$event->customer->id;$event->customer->priceList?->id;// Doesn't work: value is empty$event->customer->priceList?->appConfigId;}
Of course I'm 100% sure that bothpriceList
andappConfigId
are notnull
. Also because, as I said, code works properly when dispatched synchronously.
Before going crazy, refactoring the code, and transforming dozens and dozens of messages to make them compatible with asynchronous sending (essentially removing every Doctrine entity), I wanted to know: is this a known behavior or a bug? Is there anything that can be done to make these properties work?
How to reproduce
Send a message which has a Doctrine entity as property and use some (nested) object value.
Possible Solution
No response
Additional Context
Customer is eventually connected to aPriceList
entity:
#[ORM\Entity]class Customer{ #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column]publicint$id; #[ORM\ManyToOne] #[ORM\JoinColumn]public ?PriceList$priceList =null;}
And this entity has an integer property$appConfigId
:
#[ORM\Entity]class PriceList{ #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column]publicint$id; #[ORM\Column(nullable:true)]public ?int$appConfigId =null;}
EDIT: indeed what's serialized is aDoctrine Proxy, I expected that sincePriceRule
isn't eager loaded. But the question remain: as soon as I access theappConfigId
value, why entity isn't loaded by Doctrine?