Updating with two GeoPoints fails correctly. (#4162)

This commit is contained in:
Anthony Mosca
2017-09-19 20:42:40 +09:30
committed by Florent Vilmart
parent 406a21e967
commit cf630ba462
3 changed files with 29 additions and 6 deletions

View File

@@ -68,8 +68,7 @@ describe('Parse.GeoPoint testing', () => {
})
});
it('geo point exception two fields', (done) => {
it('creating geo point exception two fields', (done) => {
var point = new Parse.GeoPoint(20, 20);
var obj = new TestObject();
obj.set('locationOne', point);
@@ -82,6 +81,24 @@ describe('Parse.GeoPoint testing', () => {
});
});
// TODO: This should also have support in postgres, or higher level database agnostic support.
it_exclude_dbs(['postgres'])('updating geo point exception two fields', (done) => {
var point = new Parse.GeoPoint(20, 20);
var obj = new TestObject();
obj.set('locationOne', point);
obj.save(null, {
success: (obj) => {
obj.set('locationTwo', point);
obj.save().then(() => {
fail('expected error');
}, (err) => {
equal(err.code, Parse.Error.INCORRECT_TYPE);
done();
})
}
});
});
it('geo line', (done) => {
var line = [];
for (var i = 0; i < 10; ++i) {

View File

@@ -152,7 +152,11 @@ class MongoSchemaCollection {
addFieldIfNotExists(className: string, fieldName: string, type: string) {
return this._fetchOneSchemaFrom_SCHEMA(className)
.then(schema => {
// The schema exists. Check for existing GeoPoints.
// If a field with this name already exists, it will be handled elsewhere.
if (schema.fields[fieldName] != undefined) {
return;
}
// The schema exists. Check for existing GeoPoints.
if (type.type === 'GeoPoint') {
// Make sure there are not other geopoint fields
if (Object.keys(schema.fields).some(existingField => schema.fields[existingField].type === 'GeoPoint')) {

View File

@@ -661,9 +661,11 @@ export default class SchemaController {
return this._dbAdapter.addFieldIfNotExists(className, fieldName, type).then(() => {
// The update succeeded. Reload the schema
return this.reloadData({ clearCache: true });
}, () => {
//TODO: introspect the error and only reload if the error is one for which is makes sense to reload
}, (error) => {
if (error.code == Parse.Error.INCORRECT_TYPE) {
// Make sure that we throw errors when it is appropriate to do so.
throw error;
}
// The update failed. This can be okay - it might have been a race
// condition where another client updated the schema in the same
// way that we wanted to. So, just reload the schema