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

RealmResults (from Realm live queries) no longer notify UI observers #3602

Open
uixiu opened this issue May 9, 2024 · 5 comments
Open

RealmResults (from Realm live queries) no longer notify UI observers #3602

uixiu opened this issue May 9, 2024 · 5 comments

Comments

@uixiu
Copy link

uixiu commented May 9, 2024

What happened?

I am not sure if this is a bug or a feature side effect, anyway I'm building a significant product feature (live queries) based on the previous version's behavior. Feel free to change Label accordingly.
This is a miniature project for example usage

Consider the attached code snippets or linked example project;

Before version 12.0.0 ( <= 11.7.0), when adding or deleting objects to database, the list box is populated and updated correctly,
When upgraded to version 12.0.0 or above, the listbox is neither populated nor updated after object removal. On my full-fledged project, list boxes and data grids are sometimes populated, but are not always updated after deletions.

Repro steps

Compile and run linked example projects(Visual Studio 2022 is required for WinUI )

Version

12.1.0

What Atlas Services are you using?

Local Database only

What type of application is this?

Other

Client OS and version

Windows 11 Pro 23H2 - 22631.3447

Code snippets

public partial class Cat : IRealmObject
{
    [PrimaryKey]
    public ObjectId Id { get; set; } = ObjectId.GenerateNewId();
    public string Name { get; set; } = string.Empty;
    public int Age { get; set; } = 0;
    public string Breed { get; set; } = string.Empty;
}
 public partial class MainWindowViewModel : ObservableObject
 {
     public MainWindowViewModel()
     {
         var config = new RealmConfiguration(@"d:\temp\cats.realm");
         _localRealm = Realm.GetInstance(config);
         CatsQuery = _localRealm.All<Cat>();
     }

     private Realm _localRealm;

     [ObservableProperty] 
     private IQueryable<Cat> _catsQuery;
     
     public Cat? SelectedCat { get; set; }

     [RelayCommand]
     private void RemoveCat()
     {
         if (SelectedCat == null)
             return;
         _localRealm.Write(() => { _localRealm.Remove(SelectedCat); });
     }

     [RelayCommand]
     public void Populate()
     {
         Cat ninja = new() { Name = "Ninja", Age = 1, Breed = "Angora" };
         Cat nounou = new() { Name = "Nounou", Age = 2, Breed = "Siamese" };

         _localRealm.Write(() => _localRealm.Add(nounou));
         _localRealm.Write(() => _localRealm.Add(ninja));
     }
 }
<Window
    x:Class="RealmWinUI.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
        <Button Content="Populate" Command="{x:Bind MainViewModel.PopulateCommand}" />
        <Button Content="Delete" Command="{x:Bind MainViewModel.RemoveCatCommand}" />

        <ListBox ItemsSource="{x:Bind  MainViewModel.CatsQuery}"
                 DisplayMemberPath="Name"
                 SelectedItem="{x:Bind MainViewModel.SelectedCat, Mode=TwoWay}"/>
    </StackPanel>
</Window>

Stacktrace of the exception/crash you're getting

No response

Relevant log output

No response

Copy link

sync-by-unito bot commented May 9, 2024

➤ PM Bot commented:

Jira ticket: RNET-1146

@uixiu uixiu changed the title RealmResults (Realm Queries) no longer notify observers RealmResults (from Realm live queries) no longer notify UI observers May 9, 2024
@uixiu
Copy link
Author

uixiu commented May 14, 2024

When I compile my project against x64, the program behaves as expected
Going back to x86, causes collections bindings and SubscribeForNotifications issues reappear.

@nirinchev
Copy link
Member

Are you running the x86 version on an x86 machine or on a x64 one?

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label May 22, 2024
@sync-by-unito sync-by-unito bot added the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label May 22, 2024
@uixiu
Copy link
Author

uixiu commented May 22, 2024

Are you running the x86 version on an x86 machine or on a x64 one?

Thanks for your reply
I am running the x86 version on an x64 machine (Windows 11-x64, intel 12900H processor)

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels May 22, 2024
@nirinchev
Copy link
Member

Okay, I can reproduce this running x86 on Arm64 - will try and investigate further.

@sync-by-unito sync-by-unito bot removed the Needs-Attention Reporter has responded. Review comment. label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants