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

Can't get change notification for LinkingObjects #7495

Closed
pavel-ship-it opened this issue Oct 21, 2021 · 2 comments
Closed

Can't get change notification for LinkingObjects #7495

pavel-ship-it opened this issue Oct 21, 2021 · 2 comments

Comments

@pavel-ship-it
Copy link
Contributor

pavel-ship-it commented Oct 21, 2021

How frequently does the bug occur?

All the time

Description

Cannot get notification for keyPaths of a property declared as follows

// ...
    @Persisted(originProperty: "objectCol")
    var linkingObjects: LinkingObjects<ModernAllTypesObject>
// ...
    let tokenA = object.observe(keyPaths: ["linkingObjects"], changeBlock)
    let tokenAB = object.observe(keyPaths: [\ModernAllTypesObject.objectCol], changeBlock)
// ...

Stacktrace & log output

n/a

Can you reproduce the bug?

Yes, always

Reproduction Steps

I use the test case:

    func testLinkingObjectObservation() {
        let realm = realmWithTestPath()
        let objectA = ObjectWithLinking()
        let objectB = ObjectWithLinking()
        try! realm.write {
            realm.add(objectA)
            realm.add(objectB)
            objectA.objectCol = objectB
        }

        let ex_a1 = expectation(description: "linkingObjects should change")
        let ex_a2 = expectation(description: "objectCol should change")
        let ex_b = expectation(description: "linkingObjects property should change")
        let a1 = objectA.observe(keyPaths: [\ModernAllTypesObject.linkingObjects]) { _ in
            ex_a1.fulfill()
        }
        let a2 = objectA.observe(keyPaths: ["linkingObjects"]) { _ in
            ex_a2.fulfill()
        }
        let b = objectA.observe(keyPaths: [\ModernAllTypesObject.objectCol]) { _ in
            ex_b.fulfill()
        }
        try! realm.write {
            objectA.objectCol = nil
        }

        waitForExpectations(timeout: 2, handler: nil)
        a1.invalidate()
        a2.invalidate()
        b.invalidate()
    }

Version

10.17.0

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

Any iOS, MacOS

Build environment

Xcode version: 13
Dependency manager and version: n/a

@ejm01
Copy link
Contributor

ejm01 commented Oct 21, 2021

@pavel-ship-it
I got this one here.

@pavel-ship-it
Copy link
Contributor Author

Thanks @ericjordanmossman
I close it as duplicate of #7493

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants