Skip to content

Commit a4b02c8

Browse files
committed
Use __key__ instead for the attribute name for custom keys
1 parent 224438d commit a4b02c8

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

appengine_fixture_loader/loader.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ def _load(od):
4848
for attribute_name in [k for k in od.keys()
4949
if not k.startswith('__') and
5050
not k.endswith('__')]:
51-
if attribute_name == '_key':
52-
obj.key = ndb.Key(*od[attribute_name])
53-
else:
54-
attribute_type = objtype.__dict__[attribute_name]
55-
attribute_value = _sensible_value(attribute_type,
56-
od[attribute_name])
57-
obj.__dict__['_values'][attribute_name] = attribute_value
51+
attribute_type = objtype.__dict__[attribute_name]
52+
attribute_value = _sensible_value(attribute_type,
53+
od[attribute_name])
54+
obj.__dict__['_values'][attribute_name] = attribute_value
55+
56+
# set custom key if specified
57+
if '__key__' in od.keys():
58+
obj.key = ndb.Key(*od['__key__'])
5859

5960
if post_processor:
6061
post_processor(obj)

tests/customers.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[
22
{
33
"name": "John",
4-
"_key": ["Customer", "john"]
4+
"__key__": ["Customer", "john"]
55
},
66
{
77
"name": "Jane",
8-
"_key": ["Customer", "jane"]
8+
"__key__": ["Customer", "jane"]
99
}
1010
]

tests/purchases.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[
22
{
33
"price": 100,
4-
"_key": ["Customer", "john", "Purchase", "100"]
4+
"__key__": ["Customer", "john", "Purchase", "100"]
55
},
66
{
77
"price": 50,
8-
"_key": ["Customer", "jane", "Purchase", "50"]
8+
"__key__": ["Customer", "jane", "Purchase", "50"]
99
}
1010
]

0 commit comments

Comments
 (0)