Closed jhahn closed 1 year ago
Did a little more digging.
It looks like a variable scoping issue. When the object key matches the metadata constant (@metadata
), skipTypes
is clobbered, forever set to true
until the recursive function finishes.
We were able to work around the issue by making this change:
let innerSkipTypes = skipTypes
if (!skipTypes) {
innerSkipTypes = key === CONSTANTS.Documents.Metadata.KEY;
}
const fullPath = objPathPrefix ? `${objPathPrefix}.${nestedTypeInfoKey}` : nestedTypeInfoKey;
result[key] = this._makeObjectLiteral(obj[key], fullPath, typeInfoCallback, knownTypes, innerSkipTypes);
@jhahn Fixed. This for reporting this issue and very clear explanation and solution suggestion.
Exposition
We’re loading existing documents and setting “new” fields to Date values. (e.g. fields that didn’t exist on the document when it was created)
When those documents are saved, their metadata is not updated with the type information for the newly added fields.
On subsequent loads, Date values are not cast, and instead returned as stings.
This seems like an oversight, as type information is correctly extracted and stored on create.
Failing test case