Save model on node server with createdAt being new Date()
Model is saved
Got error
Error: LicenseRequestModel.createdAt must be of type 'date', got 'object' (Tue Mar 17 2020 20:03:14 GMT+0100 (Central European Standard Time))
Try to create new model on node server with new Date()
static create<T>(this: RealmModelThis<T>, realm: Realm, props: any): T {
return realm.create<T>(
this.schema.name,
{
...props,
createdAt: new Date(),
modifiedAt: new Date()
},
Realm.UpdateMode.All
);
}
Workaround for now was to use int and store date as a number. 馃槩
@bimusiek Could you post the schema?
@bimusiek We have release v5.0.0. Please try to upgrade.
I will check, thanks.
And do you know @kneth when are your team planning to release 4.0.0 beta with Node 13 support? 3.7.0 seems to work with newest node already.
@kneth With 5.0.0 there is the same issue.
Error: LicenseRequestModel.subscriptionExpiresAt must be of type 'date?', got 'object' (Thu Mar 12 2020 11:48:52 GMT+0100 (Central European Standard Time))
Schema:
public static schema = {
...BaseModel.schema,
name: 'LicenseRequestModel',
primaryKey: 'licenseId',
properties: {
...BaseModel.schema.properties,
licenseId: 'string',
token: { type: 'string', default: '' },
email: { type: 'string', default: '' },
status: { type: 'int', default: LicenseRequestStatus.INITIALIZED },
type: { type: 'int', default: LicenseRequestType.WEB },
hasSubscription: { type: 'bool', default: false },
subscriptionExpiresAt: 'date?'
}
};
export abstract class BaseModel {
public static schema = {
properties: {
createdAt: 'int',
modifiedAt: 'int'
}
};
@bimusiek Thank you for the update. Could you try subscriptionExpiresAt: { type: 'date', optional: true} instead. If that works, we have a bug in the schema parser, and if it does, the bug is in the object creation code.
Unfortunately, the same issue.
We use JS, Realm 5 and date, date? are ok. E.g.
const schema = [
{
name: "Something",
properties: {
data: "string",
createdAt: "date",
changedAt: "date?"
}
}];
Realm.open(schema);
Then create, update etc. is OK.
It looks like the issue is how we interact with classes rather than a Date issue. @bimusiek Can you try to write your schema as suggested in https://github.com/realm/realm-js/issues/2755#issuecomment-603070264
@kneth The schema I pass to Realm constructor is
const realmConfig = user.createConfiguration({
schema,
schemaVersion,
sync: {
url: `~/app`,
fullSynchronization: true
}
});
const realm = new Realm(realmConfig);
where schema is:
export const schema = [
ConfigRealmModel.schema,
CollectionModel.schema,
CollectionItemModel.schema,
ImporterAuthenticationModel.schema,
TransferModel.schema,
TransferCollectionModel.schema,
TransferCollectionItemModel.schema,
LicenseRequestModel.schema
];
export const schemaVersion = 1;
So as I understand, it is done in the same manner by passing JS object directly.
Also, it worked with 4.0.0 alpha.
I forgot to mention that I use in memory realm for Jest tests, maybe there is an issue?
I forgot to mention that I use in memory realm for Jest tests, maybe there is an issue?
I'm also running into this issue only while using an in-memory Realm for Jest tests.
Facing this issue myself with jest tests using inMemory Realm.
Works fine on 3.6.5
I'm also running into this issue only in jest test (in-memory or not)
the same code directly in node work fine
to get it working in jest:
new Date().toISOString();
Same having this issue in Jest only when run inmemory
@kneth I would like to propose changing label from T-Help to T-Bug
This may be related, obj.createdAt instanceof Date returns false. When using Realm 3.6.5 this returned true. Debugging reveals all the functions of Date are there.
I am also facing this issue with
Hi @kneth any update on the above issue, I am also facing same issue with below configuration.
Works fine on 3.6.5.
@bharadwajagali No real progress. Mostly because we are migrating to MongoDB Realm Cloud as our future platform.
this was fixed and will be part or our next release
Hey guys, I'm facing the same issue with Realm 6.1.5 when running on Jest. This was supposed to be fixed, right @blagoev?
Thanks in advance!
@McFlyssss Yes, it should be fixed.
Could you try to build from source: npm install --build-from-source --save [email protected]
Currently we support node v10 which has end-of-life late April next year. After that we can bump the N-API version to 5. But building from source using node v12 (or later), you will N-API version 5 (or later), and my hypothesis is that another code plan is exercised with version 5 (or later).
Dear @kneth ,
Thank you so much for your answer. Sorry I could not get back to it earlier.
Unfortunately, this raises the same exception. Any other idea?
@McFlyssss It might be related to Jest (see https://github.com/facebook/jest/issues/2549) and unfortunately I don't have a simple solution (but it might be worth to read https://github.com/realm/realm-js/issues/2490#issuecomment-555994222).
FYI I tried with Realm v10 and having the exact same problem. I'll take a look at those links you shared @kneth
@McFlyssss When you have had time to investigate, you are welcome to open a new issue with your observations.
So finally got it working.
Updating the node version made it work. I was running on 10.16.3 and now I'm at 10.22.1.
It seems there are some changes in regards to dates on 10.17: https://github.com/nodejs/node/pull/25917
Most helpful comment
I'm also running into this issue only in jest test (in-memory or not)
the same code directly in node work fine
to get it working in jest: