Closed VikasReactNative closed 7 months ago
My guess is that your data model has links, and Array.from()
does not copy deeply. It might be better to use the spread operator if you really need to copy the objects.
i have tried but having same issue
realm = await openRealm(); const response = realm.objects('Place'); const businesses = [...response]; // Array.from(response); if (Array.isArray(businesses) && businesses.length > 0) { const formattedAddressWords = businesses[0]?.formattedAddress?.length > 0 && businesses[0]?.formattedAddress?.split(' '); const lastWord = formattedAddressWords[formattedAddressWords.length - 1]; dispatch(setLocation(lastWord)); fetchAllPlacesDetails(businesses); dispatch(setPlacesDataLength(businesses.length)); realm.close()
The issue is that neither Array.from()
or ...
will create true POJOs, and once you close the Realm (realm.close()
), any managed (Realm) objects will be invalidated.
The following code snippet illustrates it:
const Realm = require("realm");
const A = {
name: "A",
properties: {
a: "int",
},
};
const B = {
name: "B",
properties: {
a: "A",
b: "int",
},
};
let realm = new Realm({ schema: [A, B] });
realm.write(() => {
realm.create("B", { b: 11, a: { a: 22 } });
});
let bs = realm.objects("B");
let pojos1 = [...bs];
console.log(`Before close: ${pojos1[0] instanceof Realm.Object} ${pojos1[0].a instanceof Realm.Object}`);
let pojos2 = bs.toJSON();
realm.close();
console.log(`After close: ${pojos2[0] instanceof Realm.Object} ${pojos2[0].a instanceof Realm.Object}`);
If you need to copy deeply from Realm, toJSON()
is your best option.
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.
How frequently does the bug occur?
Always
Description
const realm = Realm.open({ schema: [ PlaceSchema, LocationSchema, ContactInformationSchema, EditorialSummarySchema, ReviewSchema, PhotoSchema, AuthorAttributionSchema, TextSchema, displayNameSchema, ], deleteRealmIfMigrationNeeded: true, }); try { const places = realm.objects('Place'); // Retrieve all 'Place' objects const placesArray = Array.from(places); console.log('Data fetched from Realm:', placesArray); return placesArray; } catch (error) { console.error('Error fetching data from Realm:', error); } finally { realm.close(); }
expected realm should close but it throw error
Error: Transaction_ended and app crash
and some times=> Error: List is no longer valid. Either the parent object was deleted or the containing Realm has been invalidated or closed.
Stacktrace & log output
Can you reproduce the bug?
Always
Reproduction Steps
just read data from real and close request =>Error: transaction_ended
Version
12.5.0
What services are you using?
Atlas App Services: Functions or GraphQL or DataAPI etc
Are you using encryption?
No
Platform OS and version(s)
android
Build environment
Which debugger for React Native
Cocoapods version
No response