Skip to content
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

add failing test for serializing created_at event property #471

Closed
wants to merge 1 commit into from

Conversation

Ahrengot
Copy link
Contributor

@Ahrengot Ahrengot commented Jun 20, 2024

Hi there!

I encountered this bug when I was trying to store a collection of Eloquent models as events (Long story...)

If you define a stored event property with the name created_at, it will be set to null when the event is serialiazed.

I've been digging through the code, trying to figure out why this happens and found the following:

The ObjectNormalizer uses the PropertyAccessor from Symfony, and setting the following line (In the Symfony package) to false will fix the behavior:
https://github.com/symfony/property-access/blob/7.1/PropertyAccessor.php#L472

The ObjectNormalizer is triggering the PropertyAccessor on this line:
https://github.com/spatie/laravel-event-sourcing/blob/main/src/Support/ObjectNormalizer.php#L55

Do you know if there is a way to configure this from outside? I'm open to contributing a fix myself, but I'm a little out of my comfort zone, and I don't want to reinvent any wheels unnecessarily 😄

@Ahrengot
Copy link
Contributor Author

Ahrengot commented Jun 20, 2024

I think I understand what's going on now.

The magic getter in PropertyAccessor is capturing ShouldBeStored::createdAt():
https://github.com/spatie/laravel-event-sourcing/blob/main/src/StoredEvents/ShouldBeStored.php#L27-L30

Is there any way around that?

@sebastiandedeyne
Copy link
Member

Unfortunately I don't think so. I wrestled with similar issues with the Symfony package in the past but didn't get far.

I'm not sure this is something we can/should fix now. This seems like a niche issue that would disappear in a next major version by not having Symfony's serializer as default, and improving how we deal with created at dates because there are a few inconsistencies that need to be ironed out.

@freekmurze freekmurze closed this Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants