edanalytics / lightbeam

CLI tool for validating and transmitting payloads from JSONL files into an Ed-Fi API.
Apache License 2.0
10 stars 1 forks source link

Fix - Fetch - Key filtering #32

Closed mcriscenzo closed 5 months ago

mcriscenzo commented 5 months ago

Previously, key filtering wasn't working properly.

  1. Keep_keys was defaulting to "" (empty string" rather than "*" (wildcard). This meant that if keep_keys was not specified in the command line arguments, NO keys were kept, and an empty json file was returned.

Fixed by setting the default for keep_keys to "*" rather than "" in two places.

  1. When the lists of final_keys was being calculated (payload_keys minus drop_keys), the list of payload keys was being overwritten by the list of final_keys. Later, the Fetch code compares payload_keys and final_keys; if they're the same length, it does not bother to trim down the list of keys to return. Because payload_keys was being overwritten, they always matched, and thus the drop_keys filter was never actually applied.

Fixed by making a list copy() of payload_keys rather than just re-assigning the object pointer, so that it doesn't get overwritten.

  1. Fetch was throwing an error if any of the data records being returned by the API were missing keys (attributes) that were listed in the final_keys list. While all of the records returned by a GET request SHOULD have the same sets of attributes, the code should be able to gracefully handle when this isn't the case.

Fixed by using get(key, default) rather than directly accessing the list with the key value.