Skip to content

Commit

Permalink
remove additional auto-id field
Browse files Browse the repository at this point in the history
I belive this 'hack' become unecessary after this change
[e1eae02](e1eae02)
  • Loading branch information
snopoke committed Jun 24, 2021
1 parent a8b49f7 commit 7648ab3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
4 changes: 0 additions & 4 deletions commcare_export/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,6 @@ def lookup(self, name):

def iter(jsonpath_expr=jsonpath_expr): # Capture closure
for datum in jsonpath_expr.find(self.__bindings):
# HACK: The auto id from jsonpath_rw is good, but we lose it when we do .value here,
# so just slap it on if not present
if isinstance(datum.value, dict) and 'id' not in datum.value:
datum.value['id'] = jsonpath.AutoIdForDatum(datum).value
yield datum
return RepeatableIterator(iter)

Expand Down
8 changes: 2 additions & 6 deletions tests/test_minilinq.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,11 @@ def test_eval_auto_id_reference_nested(self):
Reference("id"), Reference('baz'), Reference('$.id'), Reference('$.foo.id'), Reference('$.foo.name')
]))
self.check_case(mmap.eval(env), [
['1.bar.1.bar.[0]', 'a1', '1', '1.bid', 'bob'],
['1.bar.[0]', 'a1', '1', '1.bid', 'bob'],
['1.bar.bazzer', 'a2', '1', '1.bid', 'bob']
])

# Without the additional auto id field added in JsonPathEnv the result for Reference("id") changes
# as follows:
# '1.bar.1.bar.[0]' -> '1.bar.[0]'

# With the change above AND a change to jsonpath_rw to prevent converting IDs that exist into
# With a change to jsonpath_rw to prevent converting IDs that exist into
# auto IDs (see https://github.com/kennknowles/python-jsonpath-rw/pull/96) we get the following:
# Reference("id"):
# '1.bar.bazzer' -> 'bazzer'
Expand Down

0 comments on commit 7648ab3

Please sign in to comment.