prooph / event-sourcing

Provides basic functionality for event sourced aggregates.

Home Page:http://getprooph.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use DossierAggregateRepository::get() with ID of different AR Type

basz opened this issue · comments

By accident I used an ID of a differently AR type to query with the AggregateRepository::get(id) with an ID for a different AR type will return the found AR off the incorrect type.

I got saved by the Type hinting, but shouldn't AggregateRepository return null in such a case? I think it is due to caching and/or snapshots, which bypasses detecting the types.

Not if this is a severe issue, posting for reference...

PHP Fatal error:  Uncaught TypeError: Return value of HF\Api\Infrastructure\Repository\Dossier\DossierAggregateRepository::get() must be an instance of HF\Api\Domain\Dossier\Aggregate\Dossier or null, instance of HF\Api\Domain\Dossier\Aggregate\Order returned in /home-projects/api-plhw-testing/deploy/releases/20181023091400UTC/src/Infrastructure/Repository/Dossier/DossierAggregateRepository.php:37
Stack trace:
#0 /home-projects/api-plhw-testing/deploy/releases/20181023091400UTC/src/Domain/Dossier/Command/Handler/RemoveAttachmentFromDossierHandler.php(44): HF\Api\Infrastructure\Repository\Dossier\DossierAggregateRepository->get(Object(HF\Api\Domain\Dossier\VO\DossierId))
#1 /home-projects/api-plhw-testing/deploy/releases/20181023091400UTC/vendor/prooph/service-bus/src/CommandBus.php(47): HF\Api\Domain\Dossier\Command\Handler\RemoveAttachmentFromDossierHandler->__invoke(Object(HF\Api\Domain\Dossier\Command\RemoveAttachmentFromDossier))
#2 /home-projects/api-plhw-testing/deploy/releases/20181023091400UTC/vendor/prooph/common/src/ in /home-projects/api-plhw-testing/deploy/releases/20181023091400UTC/vendor/prooph/service-bus/src/Exception/MessageDispatchException.php on line 26

Not a duplicate. Honest mistake... I accidentaly entered the ID of a different AR type and was that AR was returned. If it wasn't in the snapshot store it would probably return null.

So you think its a non issue?

Not really an issue. Use distinct snapshot tables for each ar if you don't like it.