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

[Bug]: HasErrors is incorrect when performing a side effect from WhenAnyPropertyChanged #515

Open
jhimes144 opened this issue Mar 15, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@jhimes144
Copy link

jhimes144 commented Mar 15, 2023

Describe the bug 🐞

        [Reactive]
        public double MaxValue { get; set; }
        
        [Reactive]
        public double MinValue { get; set; }

If I were to have the above code (code weaved to be a notify property at build time) and I were to write:

var minMaxObs = this.WhenAnyValue(v => v.MinValue, v => v.MaxValue,
      (min, max) => min < max)

this.ValidationRule(v => v.MaxValue, minMaxObs,
      "Value must be less than max value.");

this.WhenAnyPropertyChanged("MaxValue").Subscribe(_ => {
// save to database here
});

Then when inside my subscribe callback HasErrors is false when a validation error has occurred. It seems like the state of HasErrors is behind one, because if the property is updated again and still invalid, HasErrors will be true.

I've tried re-ordering my observables so that validation rules were last, that didn't work.

EDIT:
This seems to be caused by WhenAnyPropertyChanged being called before WhenAnyValue, even though the order that subscribers are set up are right. This may be an upstream issue. A workaround I found is dispatching on the UI thread the subscription of the 'WhenAnyPropertyChanged' callback. I'm using WhenAnyPropertyChanged because I have a framework I created where properties marked with a specified attribute automatically save changes to the database, without requiring me to make observables for all of them.

Step to reproduce

Create a notifiable property and subscribe to changes via ReactiveUI WhenAnyPropertyChanged extension. Notice that validation status is wrong within subscription callback.

Reproduction repository

https://github.com/reactiveui/ReactiveUI

Expected behavior

HasErrors should correctly reflect validation status.

Screenshots 🖼️

No response

IDE

No response

Operating system

Windows

Version

11

Device

PC

ReactiveUI Version

3.1.7

Additional information ℹ️

No response

@jhimes144 jhimes144 added the bug Something isn't working label Mar 15, 2023
@jhimes144 jhimes144 changed the title [Bug]: HasErrors is incorrect when performing a side effect from a property change event [Bug]: HasErrors is incorrect when performing a side effect from WhenAnyPropertyChanged Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant