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

Failed update persists entity attributes #11201

Closed
hypeJunction opened this issue Aug 24, 2017 · 12 comments
Closed

Failed update persists entity attributes #11201

hypeJunction opened this issue Aug 24, 2017 · 12 comments

Comments

@hypeJunction
Copy link
Contributor

$ia = elgg_set_ignore_access(false);
$user->language = 'de';
$user->save(); // false

echo $user->language; // de
echo get_entity($user->guid)->language; // en

The problem is that subsequent calls to other methods that do not require permissions checks could propagate these attributes to caches.

@hypeJunction hypeJunction changed the title Failed updated persists entity attributes Failed update persists entity attributes Aug 24, 2017
@mrclay
Copy link
Member

mrclay commented Aug 24, 2017

So we either revert attributes on a failed save, or provide a revert() method and beg plugins to use it. Any other ideas?

@mrclay
Copy link
Member

mrclay commented Aug 24, 2017

We might want to add $entity->hasUnsavedChanges() and have entity caches check it. I'd prefer that instead of resetting attributes in a way that might surprise devs.

@hypeJunction
Copy link
Contributor Author

We should start throwing exceptions, IMO. Ideally we would have a set of HTTP exceptions, which would be caught in router. Failing silently is not an option anymore.

@mrclay
Copy link
Member

mrclay commented Aug 24, 2017

You mean if a plugin uses permissions in a valid way to block a save(), we should throw? Of course, plugins can try/catch a FailedSaveException, but it's a big BC break.

@hypeJunction
Copy link
Contributor Author

Plugins should only be saving in actions, that would be caught by the router. So, we are just making their lives easier.

@mrclay
Copy link
Member

mrclay commented Aug 24, 2017

Legacy written actions would lose custom error messages and, more importantly, any work that came after, or partial Ajax response data that was going to be returned. These aren't reasons not to change, but considerations we can't ignore.

@hypeJunction
Copy link
Contributor Author

Let's stick with untestable code that has a brain of its own. Maybe in another 20 years we will finally learn

@mrclay
Copy link
Member

mrclay commented Aug 24, 2017

save() returning false doesn't make it untestable. It's a trade off like everything else. The greater crime toward untestability is all the invisible caching. I gave a solution above that I could try.

@mrclay
Copy link
Member

mrclay commented Aug 24, 2017

Another: the moment an attribute is changed, purge the entity cache of it and disable caching for it. Leave it to be cached on a later request.

This is functionally the same as above though. We want to mark the entity dirty for the rest of the request.

@jdalsem
Copy link
Member

jdalsem commented Aug 29, 2017

will this still be a problem when the attributes have been moved to metadata?

@hypeJunction
Copy link
Contributor Author

will this still be a problem when the attributes have been moved to metadata?

It would for user entities

hypeJunction added a commit to hypeJunction/Elgg-leaf that referenced this issue Jun 19, 2018
Entities, metadata, annotations and relationships are now consistent in their
lifecycle events. To avoid confusion, create, update and delete events have been
deprecated, instead plugins should use create:before, create:after, update:before
, update:after, delete:before and delete:after events.
This also eliminates the bad practice of deleting rows from database right after
they have been created, should a handler return false.

Also updates entity save operations to throw HttpExceptions when problems occur.
Failed entity update now resets entity attributes to their originals.

Fixes Elgg#11201
Fixes Elgg#9033
Fixes Elgg#7997
hypeJunction added a commit to hypeJunction/Elgg-leaf that referenced this issue Jun 19, 2018
Entities, metadata, annotations and relationships are now consistent in their
lifecycle events. To avoid confusion, create, update and delete events have been
deprecated, instead plugins should use create:before, create:after, update:before
, update:after, delete:before and delete:after events.
This also eliminates the bad practice of deleting rows from database right after
they have been created, should a handler return false.

Also updates entity save operations to throw HttpExceptions when problems occur.
Failed entity update now resets entity attributes to their originals.

Fixes Elgg#11201
Fixes Elgg#9033
Fixes Elgg#7997
hypeJunction added a commit to hypeJunction/Elgg-leaf that referenced this issue Jun 19, 2018
Entities, metadata, annotations and relationships are now consistent in their
lifecycle events. To avoid confusion, create, update and delete events have been
deprecated, instead plugins should use create:before, create:after, update:before
, update:after, delete:before and delete:after events.
This also eliminates the bad practice of deleting rows from database right after
they have been created, should a handler return false.

Also updates entity save operations to throw HttpExceptions when problems occur.
Failed entity update now resets entity attributes to their originals.

Fixes Elgg#11201
Fixes Elgg#9033
Fixes Elgg#7997
@jdalsem
Copy link
Member

jdalsem commented Oct 4, 2021

There is no clear direction for a solution for now. If using save() do not assume it is successful

@jdalsem jdalsem closed this as completed Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants