The PUT method for the /archives endpoint has some odd behaviors that seem to be causing issues with data retrieval.
def put(self) -> Dict[str, str]:
#...
json_data = request.get_json()
data = json.loads(json_data)
id = data["id"] if "id" in data else None
last_cached = data["last_cached"] if "last_cached" in data else None
broken_as_of = (
data["broken_source_url_as_of"]
if "broken_source_url_as_of" in data
else None
)
with self.setup_database_client() as db_client:
response = update_archives_data(db_client, id, last_cached, broken_as_of)
This requires the dictionary entry to be "dumped" beforehand, as in update_pdap_archives in cache_url.py of the pdap-automatic-archives repository:
def update_pdap_archives(entry: dict):
"""
Update data in PDAP archives
:param entry:
:return:
"""
entry_json = json.dumps(entry)
response = requests.put(
f"{os.getenv('VITE_VUE_APP_BASE_URL')}/archives",
json=entry_json,
headers={"Authorization": API_KEY},
)
response.raise_for_status()
``
Other resources don't require this. For example, in the `PUT` method for the `DataSourceById` resource class in `DataSources.py`:
```python
def put(self, data_source_id: str) -> Response:
# ...
data = request.get_json()
with self.setup_database_client() as db_client:
return update_data_source_wrapper(db_client, data, data_source_id)
And it is thus easier to make a response, as seen in test_data_sources_by_id.py in tests/integration:
By contrast, if you attempt to do something like this with the archives PUT method, you'll get the error: the JSON object must be str, bytes or bytearray, not dict.
So the Archives PUT method appears to require extra steps which are immediately reversed in the backend. This makes request-making more difficult and makes documentation more challenging: currently, the Gitbook documentation doesn't mention this step.
TODO
[ ] Revise Archives PUT method to not need the json.loads() step
[ ] Revise associated Archives tests to not perform the json.dumps() step
[ ] Revise update_pdap_archives in cache_url.py of the pdap-automatic-archives repository to also not perform json.dumps()
The
PUT
method for the/archives
endpoint has some odd behaviors that seem to be causing issues with data retrieval.This requires the dictionary entry to be "dumped" beforehand, as in
update_pdap_archives
incache_url.py
of the pdap-automatic-archives repository:And it is thus easier to make a response, as seen in
test_data_sources_by_id.py
intests/integration
:By contrast, if you attempt to do something like this with the archives
PUT
method, you'll get the error:the JSON object must be str, bytes or bytearray, not dict.
So the Archives
PUT
method appears to require extra steps which are immediately reversed in the backend. This makes request-making more difficult and makes documentation more challenging: currently, the Gitbook documentation doesn't mention this step.TODO
PUT
method to not need thejson.loads()
stepjson.dumps()
stepupdate_pdap_archives
incache_url.py
of the pdap-automatic-archives repository to also not performjson.dumps()