Skip to content

Commit 019f9e5

Browse files
davimacedoflovilmart
authored andcommitted
Fix(MongoTransform): Ignore Audience legacy fields (#4018)
1 parent 121d151 commit 019f9e5

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

spec/AudienceRouter.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,40 @@ describe('AudiencesRouter', () => {
284284
}
285285
);
286286
});
287+
288+
it_exclude_dbs(['postgres'])('should not log error with legacy parse.com times_used and _last_used fields', (done) => {
289+
const database = (new Config(Parse.applicationId)).database.adapter.database;
290+
const now = new Date();
291+
Parse._request('POST', 'push_audiences', { name: 'My Audience', query: JSON.stringify({ deviceType: 'ios' })}, { useMasterKey: true })
292+
.then((audience) => {
293+
database.collection('test__Audience').updateOne(
294+
{ _id: audience.objectId },
295+
{
296+
$set: {
297+
times_used: 1,
298+
_last_used: now
299+
}
300+
},
301+
{},
302+
(error) => {
303+
expect(error).toEqual(null)
304+
database.collection('test__Audience').find({ _id: audience.objectId}).toArray(
305+
(error, rows) => {
306+
expect(error).toEqual(null)
307+
expect(rows[0]['times_used']).toEqual(1);
308+
expect(rows[0]['_last_used']).toEqual(now);
309+
Parse._request('GET', 'push_audiences', {}, {useMasterKey: true})
310+
.then((results) => {
311+
expect(results.results.length).toEqual(1);
312+
expect(results.results[0].name).toEqual('My Audience');
313+
expect(results.results[0].query.deviceType).toEqual('ios');
314+
expect(results.results[0].times_used).toEqual(undefined);
315+
expect(results.results[0]._last_used).toEqual(undefined);
316+
done();
317+
})
318+
.catch((error) => { done.fail(error); })
319+
});
320+
});
321+
});
322+
});
287323
});

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,10 @@ const mongoObjectToParseObject = (className, mongoObject, schema) => {
924924
restObject['expiresAt'] = Parse._encode(new Date(mongoObject[key]));
925925
break;
926926
default:
927+
if (className === '_Audience' && (key === '_last_used' || key === 'times_used')) {
928+
// Ignore these parse.com legacy fields
929+
break;
930+
}
927931
// Check other auth data keys
928932
var authDataMatch = key.match(/^_auth_data_([a-zA-Z0-9_]+)$/);
929933
if (authDataMatch) {

0 commit comments

Comments
 (0)