Whole file
getmoto/py-partiql-parser
The author described this change as “Bug: Query DynamoDB item that contains a list”. It counts as a record because the check below fails on the code as it stood at 7af964e81 and passes on fbb7da2bc, with nothing else changed between the two runs.
Projectgetmoto/py-partiql-parser
Fix saved2023-07-29
Sharing licenceMIT · LICENSE
Change size+17 −0
What the code was meant to do, written into the code itself as a save note
Bug: Query DynamoDB item that contains a list
The change
| 1 | + | import re | |
| 2 | + | ||
| 1 | 3 | from .case_insensitive_dict import CaseInsensitiveDict | |
| 2 | 4 | from .json_parser import MissingVariable, Variable | |
| 3 | 5 | from typing import Any, Dict, List, Tuple, Union | |
| ⋯ | |||
| 77 | 79 | def find_value_in_document(keys: List[str], json_doc): | |
| 78 | 80 | if not is_dict(json_doc): | |
| 79 | 81 | return None | |
| 82 | + | key_is_array = re.search(r"(.+)\[(\d+)\]$", keys[0]) | |
| 83 | + | if key_is_array: | |
| 84 | + | key_name = key_is_array.group(1) | |
| 85 | + | array_index = int(key_is_array.group(2)) | |
| 86 | + | try: | |
| 87 | + | requested_list = json_doc.get(key_name, []) | |
| 88 | + | assert isinstance(requested_list, list) | |
| 89 | + | doc_one_layer_down = requested_list[array_index] | |
| 90 | + | except IndexError: | |
| 91 | + | # Array exists, but does not have enough values | |
| 92 | + | doc_one_layer_down = {} | |
| 93 | + | except AssertionError: | |
| 94 | + | # Requested key is not an array - fail silently just like AWS does | |
| 95 | + | doc_one_layer_down = {} | |
| 96 | + | return find_value_in_document(keys[1:], doc_one_layer_down) | |
| 80 | 97 | if len(keys) == 1: | |
| 81 | 98 | return json_doc.get(keys[0]) | |
| 82 | 99 | return find_value_in_document(keys[1:], json_doc.get(keys[0], {})) | |
The check that tells the two apart
fail→pass·tests/test_dynamodb_examples.py::test_search_object_inside_a_list
Check file tests/test_dynamodb_examples.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it7af964e811b115e7209a64f32be67720c0b194d4
Broken version dated2023-07-19
Modulepy_partiql_parser._internal.utils
Units changedfind_value_in_document
Fingerprint947910d3d658cd61
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.