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

Do not throw exception on checkState if item is deleted / set node clean after save/update. #309

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

dantleech
Copy link
Contributor

Set the node as clean after updating the node via. transport during the save() operation.

See related:

@@ -636,10 +636,6 @@ protected function checkState()
$this->postDirtyState = -1;
}

if ($this->state === self::STATE_DELETED) {
throw new InvalidItemStateException('Item '.$this->path.' is deleted');
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I guess this implies that DELETED is a valid state until you try and manipulate the node.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem with this is that when you manipulate the node, it calls checkState to make sure it can be manipulated.

looking at the stack trace in https://travis-ci.org/jackalope/jackalope-doctrine-dbal/jobs/119277489 i think the problem is something else. https://github.com/jackalope/jackalope/blob/check_state_delete_no_exception/src/Jackalope/ObjectManager.php#L1124 assumes that a node that is dirty is not deleted (because both are states). but then ->getIdentifier will trigger checkState which detects the node is deleted. i think before the deleted check in the object manager, we should check for dirty and if the node is dirty call refresh($keepChanges). then the state will not be dirty anymore but deleted or new or modified and things work as expected i'd hope.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you call refresh repeatedly, things will become very expensive as everything that is dirty is reloaded.

it smells fishy when a node is still dirty after a save() operations, btw. if that is the case there might be some other bug too.

@dantleech dantleech force-pushed the check_state_delete_no_exception branch from 418a145 to a5b08cf Compare April 4, 2016 15:06
@@ -869,6 +869,7 @@ public function save()
if ($item->isModified() || $item->isMoved()) {
$item->confirmSaved();
}
$item->setClean();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the change.

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 we did not do this so that auto generated things would be found when reloading (jackrabbit might autocreate some things)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand: do you mean if the node contains some auto-created properties? i.e. if it is dirty then the state will be reloaded somehow?

Otherwise do you think this is the correct behavior? If not, any ideas as to what we can do to fix the issue?

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 we on purpose mark the node dirty when we confirm it its saved. there are autocreated properties in the backend, e.g. the uuid if you did not force creation already.

i wrote about the solution that i expect to be correct in a comment that is now hidden:

looking at the stack trace in https://travis-ci.org/jackalope/jackalope-doctrine-dbal/jobs/119277489 i think the problem is something else. https://github.com/jackalope/jackalope/blob/check_state_delete_no_exception/src/Jackalope/ObjectManager.php#L1124 assumes that a node that is dirty is not deleted (because both are states). but then ->getIdentifier will trigger checkState which detects the node is deleted. i think before the deleted check in the object manager, we should check for dirty and if the node is dirty call refresh($keepChanges). then the state will not be dirty anymore but deleted or new or modified and things work as expected i'd hope.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dantleech can we do the solution i propose in my last comment, or does that lead to some other problem?

@dantleech
Copy link
Contributor Author

@dbu have updated - now the only change is setting the node to clean after updating it with the transport, seems to fix the issue. When the user later tries to access a property of the (deleted) node they will receive the usual InvalidItemStateException.

@dantleech dantleech changed the title Do not throw exception on checkState if item is deleted. Do not throw exception on checkState if item is deleted / set node clean after save/update. Apr 4, 2016
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.

None yet

2 participants