-
Notifications
You must be signed in to change notification settings - Fork 68
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
Attribute Watching: subtract() results in not passing the new value to the setter #453
Comments
Hey @julian99m 👋 Great question, this could definitely use more explanation on the docs!
This is fair to assume, though unfortunately not possible with a single request to DynamoDB. The setter is called prior to your mutation request to DynamoDB, so ElectroDB won't have access to the result of the subtraction (or addition) operation.
I was actually surprised to see the Let me know if this raises any additional questions you have in the meantime 👍 |
I looked into the scope of work it would take to add operation context to the values passed to To address the titular concern, I want to reiterate that any value passed to an attribute setter is a value that was |
Hi @tywalch, Thanks! :) |
Describe the bug
When calling the subtract() method on a watched attribute, the setter of the watching attribute will not be called with the new value, but rather with the value that was subtracted from the original value.
Example: original value is 5, subtract method is called with parameter 2, the setter will not be called with 3 (new value), but with 2 (parameter of the subtract-call).
ElectroDB Version
3.0.1
ElectroDB Playground Link
ElectroDB Playground
(The behavior can be observed in the resulting update operation)
Entity/Service Definitions
see Playground
Expected behavior
Without further explanation in the docs, I would expect the new value (3) to be passed to the setter.
If the observed behavior is correct, it should be explicitly mentioned in the docs. But as the operation is not given in the setter callback, the provided value can not be interpreted and thus holds no valuable information, so I think the behavior should be changed, if possible.
The text was updated successfully, but these errors were encountered: