summaryrefslogtreecommitdiff
path: root/jsonpath_rw/jsonpath.py
diff options
context:
space:
mode:
authorSimon Kelly <skelly@dimagi.com>2021-06-24 11:21:42 +0200
committerSimon Kelly <skelly@dimagi.com>2021-06-24 11:21:55 +0200
commit08231fb66f73b83a2b5a1acc2abef49ca3be3b4c (patch)
tree6c99504715ad60f36ea9edd3a926541cddfe7743 /jsonpath_rw/jsonpath.py
parent749d123ab37a0fa7593f50058a90f6fa477dcc51 (diff)
downloadjsonpath-rw-08231fb66f73b83a2b5a1acc2abef49ca3be3b4c.tar.gz
don't clobber IDs if they exist
If a field exists with the name of the `auto_id_field` it should be used as is without converting it to an AutoID. The auto ID functionality should only kick in if and ID field does not exist.
Diffstat (limited to 'jsonpath_rw/jsonpath.py')
-rw-r--r--jsonpath_rw/jsonpath.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/jsonpath_rw/jsonpath.py b/jsonpath_rw/jsonpath.py
index c47653e..1d4ac4c 100644
--- a/jsonpath_rw/jsonpath.py
+++ b/jsonpath_rw/jsonpath.py
@@ -430,14 +430,13 @@ class Fields(JSONPath):
self.fields = fields
def get_field_datum(self, datum, field):
- if field == auto_id_field:
- return AutoIdForDatum(datum)
- else:
- try:
- field_value = datum.value[field] # Do NOT use `val.get(field)` since that confuses None as a value and None due to `get`
- return DatumInContext(value=field_value, path=Fields(field), context=datum)
- except (TypeError, KeyError, AttributeError):
- return None
+ try:
+ field_value = datum.value[field] # Do NOT use `val.get(field)` since that confuses None as a value and None due to `get`
+ return DatumInContext(value=field_value, path=Fields(field), context=datum)
+ except (TypeError, KeyError, AttributeError):
+ if field == auto_id_field:
+ return AutoIdForDatum(datum)
+ return None
def reified_fields(self, datum):
if '*' not in self.fields: