Skip to content

Commit cf630ba

Browse files
aontasflovilmart
authored andcommitted
Updating with two GeoPoints fails correctly. (#4162)
1 parent 406a21e commit cf630ba

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

spec/ParseGeoPoint.spec.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ describe('Parse.GeoPoint testing', () => {
6868
})
6969
});
7070

71-
72-
it('geo point exception two fields', (done) => {
71+
it('creating geo point exception two fields', (done) => {
7372
var point = new Parse.GeoPoint(20, 20);
7473
var obj = new TestObject();
7574
obj.set('locationOne', point);
@@ -82,6 +81,24 @@ describe('Parse.GeoPoint testing', () => {
8281
});
8382
});
8483

84+
// TODO: This should also have support in postgres, or higher level database agnostic support.
85+
it_exclude_dbs(['postgres'])('updating geo point exception two fields', (done) => {
86+
var point = new Parse.GeoPoint(20, 20);
87+
var obj = new TestObject();
88+
obj.set('locationOne', point);
89+
obj.save(null, {
90+
success: (obj) => {
91+
obj.set('locationTwo', point);
92+
obj.save().then(() => {
93+
fail('expected error');
94+
}, (err) => {
95+
equal(err.code, Parse.Error.INCORRECT_TYPE);
96+
done();
97+
})
98+
}
99+
});
100+
});
101+
85102
it('geo line', (done) => {
86103
var line = [];
87104
for (var i = 0; i < 10; ++i) {

src/Adapters/Storage/Mongo/MongoSchemaCollection.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ class MongoSchemaCollection {
152152
addFieldIfNotExists(className: string, fieldName: string, type: string) {
153153
return this._fetchOneSchemaFrom_SCHEMA(className)
154154
.then(schema => {
155-
// The schema exists. Check for existing GeoPoints.
155+
// If a field with this name already exists, it will be handled elsewhere.
156+
if (schema.fields[fieldName] != undefined) {
157+
return;
158+
}
159+
// The schema exists. Check for existing GeoPoints.
156160
if (type.type === 'GeoPoint') {
157161
// Make sure there are not other geopoint fields
158162
if (Object.keys(schema.fields).some(existingField => schema.fields[existingField].type === 'GeoPoint')) {

src/Controllers/SchemaController.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,11 @@ export default class SchemaController {
661661
return this._dbAdapter.addFieldIfNotExists(className, fieldName, type).then(() => {
662662
// The update succeeded. Reload the schema
663663
return this.reloadData({ clearCache: true });
664-
}, () => {
665-
//TODO: introspect the error and only reload if the error is one for which is makes sense to reload
666-
664+
}, (error) => {
665+
if (error.code == Parse.Error.INCORRECT_TYPE) {
666+
// Make sure that we throw errors when it is appropriate to do so.
667+
throw error;
668+
}
667669
// The update failed. This can be okay - it might have been a race
668670
// condition where another client updated the schema in the same
669671
// way that we wanted to. So, just reload the schema

0 commit comments

Comments
 (0)