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

Converting circular structure to JSON → starting at object with constructor #1481

Closed
Jaycyn opened this issue Mar 7, 2022 · 3 comments
Closed

Comments

@Jaycyn
Copy link

Jaycyn commented Mar 7, 2022

Describe the bug
I received this notice from MongoDB Realm Studio 11.1.1 when clicking on a class and am not sure what it means or what to do about it. I cannot view any of the objects in that class

Converting circular structure to JSON → starting at object with constructor ‘Object’ | property ‘embedded_dog_list’ → object with constructor ‘Array’ | index 0 → object with constructor ‘Object’ — property ‘parent_object’ closes the circle

To Reproduce
Here's the object structure. Note this does NOT occur on a freshly minted Realm file with no data. It only occurs after data is written.

There’s a parent Person object with embedded Dog objects (as a List), and then a City class which points back to the embedded dog list.

class PersonClass: Object {
    @Persisted var embedded_dog_list: List<EmbeddedDogClass>
and the embedded dogs look like this:

class EmbeddedDogClass: EmbeddedObject {
    @Persisted var name  = ""
    @Persisted var parent_object: AnyRealmValue = .none
    @Persisted var linked_city: CityClass!
and the City class

class CityClass: Object {
    @Persisted(originProperty: "linked_city") var linkedEmbeddedDogs: LinkingObjects<EmbeddedDogClass>

The idea here is the Persons have dogs. At the same time I want to know a person via the dog in a city. e.g. I can pull up a city, and get a list of dogs in that city, and also, through the parent_object field, know their person. (There are different types of owners, Person being one of them, which is why I used AnyRealmValue)

When loading a Person in code and printing it to console, everything looks normal and all values are as expected

Expected behavior
Show the objects of the class when clicking on the class?

Versions:

  • OS: macOS 12.0.1
  • Realm Studio: 11.1.1 (11.1.1.42)
  • SDK 10.21.0 through 10.24.0
@kneth
Copy link
Member

kneth commented Mar 8, 2022

I think the issue it that our cycle detection doesn't take AnyRealmValue into account. If it is possible for you, we would appreciate if you can verify that it works if you change the type of parent_object to PersonClass.

@Jaycyn
Copy link
Author

Jaycyn commented Mar 8, 2022

@kneth

Thanks for taking a look, I appreciate it.

Yes, changing the parent_object property of the EmbeddedDogClass to a PersonClass works correctly.

class EmbeddedDogClass: EmbeddedObject {
    @Persisted var name  = ""
    //@Persisted var parent_object: AnyRealmValue = .none
    @Persisted var parent_object: PersonClass! <- changed to
    @Persisted var linked_city: CityClass!

@kneth
Copy link
Member

kneth commented Mar 9, 2022

@visdyn Thanks for checking. We believe we understand the issue now.

@sync-by-unito sync-by-unito bot closed this as completed Dec 12, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2024
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