-
-
Notifications
You must be signed in to change notification settings - Fork 224
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
!!! TASK: Streamline ContentGraph::findRootNodeAggregateByType
#5158
!!! TASK: Streamline ContentGraph::findRootNodeAggregateByType
#5158
Conversation
to be nullable like findRootNodeByType in the subgraph
Mmm, I guess there are arguments in both directions, I generally like it as is, with the Exception, but it makes sense to have things similar between the subgraph and the content graph. |
jip my argument would be that there is no The only thing that throws is Handling nullability yourself is also way easier than knowing which exceptions to catch and which not... phpstan will help you. Im really glad that |
Good question yes, I guess in some cases were the error case is fine you can skip an additional null check, but fine for me to merge it, we need ot adapt the use cases as well though! |
@@ -60,6 +60,10 @@ public function removeSiteNode(SiteNodeName $siteNodeName): void | |||
$sitesNodeAggregate = $contentGraph->findRootNodeAggregateByType( | |||
NodeTypeNameFactory::forSites() | |||
); | |||
if (!$sitesNodeAggregate) { | |||
// nothing to prune, we could probably also return here directly? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be the current behavior with the exception I guess? Or rather we might actually throw here to tell people that this site does not exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we throw currently. But as we want to remove a child node either way it seems fine to say, well we cant remove a thing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, skipping is the better behavior.
But maybe we could throw at the end of this method if no node was actually removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think so. But with #4470 we can definitely discuss how the full behaviour should be and adjust edge cases.
Neos.Neos/Classes/Controller/Module/Administration/SitesController.php
Outdated
Show resolved
Hide resolved
Neos.ContentRepository.Core/Classes/Service/ContentRepositoryBootstrapper.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is, why was it nullable once and that has been removed??!
It was never nullable, it was introduced with:
1f4b464#diff-a623327bb4acbff32c1cbab65ef64b94e682baddd7505e56ca5f08b08e80ecc2
But it replaced the previous findRootNodeByType
that was nullable.
Mmm, I guess there are arguments in both directions
I'm also torn sometimes between exception and nullable, since the latter is slightly less explicit.
But for these cases it totally makes sense IMO (as you can tell from the simplified resulting code) and also we had that soft guideline that find*
returns nullable types and get*
throws.
Just some minor remarks that might be ignored
@@ -60,6 +60,10 @@ public function removeSiteNode(SiteNodeName $siteNodeName): void | |||
$sitesNodeAggregate = $contentGraph->findRootNodeAggregateByType( | |||
NodeTypeNameFactory::forSites() | |||
); | |||
if (!$sitesNodeAggregate) { | |||
// nothing to prune, we could probably also return here directly? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, skipping is the better behavior.
But maybe we could throw at the end of this method if no node was actually removed?
@@ -101,7 +98,7 @@ private function getNodesWithExceededDates(ContentRepository $contentRepository, | |||
$sitesNodeTypeName = NodeTypeName::fromString('Neos.Neos:Sites'); | |||
$rootNode = $subgraph->findRootNodeByType($sitesNodeTypeName); | |||
if ($rootNode === null) { | |||
throw RootNodeAggregateDoesNotExist::butWasExpectedTo($sitesNodeTypeName); | |||
throw new \RuntimeException(sprintf('No sites root node found in content repository "%s"', $contentRepository->id->value), 1719047148); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering: Why don't we keep the RootNodeAggregateDoesNotExist
exception and throw it here? (not sure if it's needed but I'm curious about your reasons to replace it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are in a different package here (the timeable stuff) and its imo not needed here to have a special exception class. Its a not ever gonna happen case and just a save guard.
…GraphFindRootNodeAggregateByType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer having find*ers nullable consistently, so +1 from me.
In this case especially, getOrCreateRootNodeAggregate (see above) gets a lot more comprehensible.
Tests should again be green as well.
to be nullable like findRootNodeByType in the subgraph
Upgrade instructions
Review instructions
I wondered why is
findRootNodeByType
in the subgraph nullable whilefindRootNodeAggregateByType
in the content graph is not nullable and throws anRootNodeAggregateDoesNotExist
exception? That seems the only place where we throw deliberately exceptions in the read side if a user of the cr put wrong stuff in the query.findRootNodeAggregateByType
was nullable introduced via 1f4b464#diff-a623327bb4acbff32c1cbab65ef64b94e682baddd7505e56ca5f08b08e80ecc2nullability was removed via 8ab8a1b#diff-a623327bb4acbff32c1cbab65ef64b94e682baddd7505e56ca5f08b08e80ecc2
last refactoring #4339 and #4129
Checklist
FEATURE|TASK|BUGFIX
!!!
and have upgrade-instructions