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

!!! TASK: Streamline ContentGraph::findRootNodeAggregateByType #5158

Conversation

mhsdesign
Copy link
Member

to be nullable like findRootNodeByType in the subgraph

Upgrade instructions

Review instructions

I wondered why is findRootNodeByType in the subgraph nullable while findRootNodeAggregateByType in the content graph is not nullable and throws an RootNodeAggregateDoesNotExist 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.

  1. findRootNodeAggregateByType was nullable introduced via 1f4b464#diff-a623327bb4acbff32c1cbab65ef64b94e682baddd7505e56ca5f08b08e80ecc2

  2. nullability was removed via 8ab8a1b#diff-a623327bb4acbff32c1cbab65ef64b94e682baddd7505e56ca5f08b08e80ecc2

last refactoring #4339 and #4129

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

to be nullable like findRootNodeByType in the subgraph
@kitsunet
Copy link
Member

kitsunet commented Jul 1, 2024

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.

@mhsdesign
Copy link
Member Author

jip my argument would be that there is no find method that throws if you try to find something that doesnt exist (because of bad user input).

The only thing that throws is getContentGraph but we discussed that we liked it there.

Handling nullability yourself is also way easier than knowing which exceptions to catch and which not... phpstan will help you. Im really glad that findParent etc are now nullable (unlike once proposed in the traversableNodeInterface) and this should probably be aligned to behave the same.
The question is, why was it nullable once and that has been removed??!

@kitsunet
Copy link
Member

kitsunet commented Jul 1, 2024

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?
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

@bwaidelich bwaidelich left a 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?
Copy link
Member

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);
Copy link
Member

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)

Copy link
Member Author

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.

@mhsdesign mhsdesign requested a review from kitsunet July 13, 2024 09:09
Copy link
Member

@nezaniel nezaniel left a 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.

@nezaniel nezaniel merged commit a023bea into neos:9.0 Jul 29, 2024
9 checks passed
@mhsdesign mhsdesign deleted the task/streamLineContentGraphFindRootNodeAggregateByType branch July 29, 2024 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants