Skip to content

Commit c741869

Browse files
stephenpluspluscallmehiphop
authored andcommitted
datastore: allow storing empty objects (#1454)
1 parent 9cdcef5 commit c741869

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

lib/datastore/entity.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,12 @@ function encodeValue(value) {
283283
return valueProto;
284284
}
285285

286-
if (is.object(value) && !is.empty(value)) {
287-
for (var prop in value) {
288-
if (value.hasOwnProperty(prop)) {
289-
value[prop] = entity.encodeValue(value[prop]);
286+
if (is.object(value)) {
287+
if (!is.empty(value)) {
288+
for (var prop in value) {
289+
if (value.hasOwnProperty(prop)) {
290+
value[prop] = entity.encodeValue(value[prop]);
291+
}
290292
}
291293
}
292294

test/datastore/entity.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,21 @@ describe('entity', function() {
430430
assert.deepEqual(entity.encodeValue(value), expectedValueProto);
431431
});
432432

433+
it('should encode an empty object', function() {
434+
var value = {};
435+
436+
var expectedValueProto = {
437+
entityValue: {
438+
properties: {}
439+
}
440+
};
441+
442+
assert.deepEqual(entity.encodeValue(value), expectedValueProto);
443+
});
444+
433445
it('should throw if an invalid value was provided', function() {
434446
assert.throws(function() {
435-
entity.encodeValue({});
447+
entity.encodeValue();
436448
}, /Unsupported field value/);
437449
});
438450
});

0 commit comments

Comments
 (0)