-
Type: Bug
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
3 - M (<= 1 month)
-
2659
What happened?
Accessing backlinks from inside a query would be expected to either throw (unsupported) or succeed, but instead it silently fails, ignoring that portion of the query and returning unwanted results.
As an aside, my goal here is to iterate over a potentially large table to truncate rows with no backlinks (while also performing external tasks). I've found that just looping over every entry in the table and checking BacklinksCount works quite well, but if there's a more performant way of handling this kind of scenario I'd love to hear it. Looping looks to take around 4s for 1m entries.
Repro steps
- Attempt to query a property marked with [Backlink] inside an IQueryable<> realm source.
- Note that the backlink condition is completely ignored, returning all results.
Version
10.5.0
What SDK flavour are you using?
Local Database only
What type of application is this?
Console/Server
Client OS and version
macOS 15 beta
Code snippets
Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
using System; using System.Linq; using Nito.AsyncEx; using Realms; using Xunit; namespace osu.Game.Tests { public class BacklinkViaQueryBugTests { [Fact] public void TestBacklinkViaQuery() { AsyncContext.Run(() => { // test with no backlinks using (var realm = Realm.GetInstance(new InMemoryConfiguration("a"))) { using (var transaction = realm.BeginWrite()) { realm.Add(new TestFile { Hash = "1" }); transaction.Commit(); } var filesList = realm.All<TestFile>().ToList(); // non-queryable so we can linq access BacklinksCount. Assert.Equal(0, filesList.Count(f => f.BacklinksCount > 0)); Assert.Equal(0, realm.All<TestFile>().Count(f => f.Usages.Any())); } }); } public class TestThingUsingFile : RealmObject { public TestFile File { get; set; } = null!; } public class TestFile : RealmObject { [PrimaryKey] public string Hash { get; set; } = String.Empty; [Backlink(nameof(TestThingUsingFile.File))] public IQueryable<TestThingUsingFile> Usages { get; } = null!; // TODO: check efficiency (ie. do we need to cache this to a count still?) } } }
Stacktrace of the exception/crash you're getting
No response
Relevant log output
No response