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

Results keypath observing ignores deletion of child object #7684

Closed
michalrentka opened this issue Mar 2, 2022 · 3 comments
Closed

Results keypath observing ignores deletion of child object #7684

michalrentka opened this issue Mar 2, 2022 · 3 comments

Comments

@michalrentka
Copy link

michalrentka commented Mar 2, 2022

How frequently does the bug occur?

All the time

Description

I have objects which are related together like this:

final class RItem: Object {
    @Persisted(indexed: true) var key: String
    @Persisted(originProperty: "item") var tags: LinkingObjects<RTypedTag>
}
final class RTag: Object {
    @Persisted(indexed: true) var name: String
    @Persisted(originProperty: "tag") var tags: LinkingObjects<RTypedTag>
}
final class RTypedTag: Object {
    enum Kind: Int, PersistableEnum {
        case automatic = 1
        case manual = 0
    }

    @Persisted var type: Kind
    @Persisted var tag: RTag?
    @Persisted var item: RItem?
}

Then I have a screen with a simple tableView which shows items, but also includes some information about tags for each item. I observe Results<RItem> and reload tableView when I receive an update:

results.observe(keyPaths: ["tags"]) { [weak self] change in
    switch change {
    case .error: return
    case .initial(let results):
        self?.reload(with: results.freeze())
    case .update(let results, _, _, _):
        self?.reload(with: results.freeze())
    }
}

private func reload(with snapshot: Results<RItem>) {
    self.snapshot = snapshot
    self.tableView.reloadData()
}

When a new RTypedTag is created and assigned to an item, the table view updates correctly. But when an RTypedTag is deleted from database, I receive no update for this change, so tableView keeps showing old state. I also tried changing the keyPaths to "tags.tag" or "tags.tag.name", but they both resulted in the same behaviour.

I'm attaching a simplified sample project, where I reproduced this issue.

Stacktrace & log output

No response

Can you reproduce the bug?

Yes, always

Reproduction Steps

See included simple project. Try to "add" and then "remove" a tag and see that tableView changes when tag is added, but it doesn't change after deletion is performed.

Version

10.23.0

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

iOS 15

Build environment

Xcode 13.2, SwiftPM

@michalrentka
Copy link
Author

RealmBug.zip

@pavel-ship-it
Copy link
Contributor

Hi @michalrentka , thank you for the report.
Looks like known issue #7493
@ericjordanmossman FYI

@pavel-ship-it
Copy link
Contributor

I close it as duplicate. Please followup the mentioned ticket

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