Skip to content

Commit

Permalink
Merge pull request #361 from uc-cdis/fix/content-date-default-to-none
Browse files Browse the repository at this point in the history
Change content date defaults to None from ''
  • Loading branch information
k-burt-uch authored Jun 9, 2023
2 parents ff55a72 + a498afa commit c6c8a73
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
5 changes: 4 additions & 1 deletion indexd/index/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,10 @@ def put_index_record(record):

rev = flask.request.args.get("rev")
json = flask.request.json
if "content_updated_date" in json and "content_created_date" in json:
if (
json.get("content_updated_date") is not None
and json.get("content_created_date") is not None
):
if json["content_updated_date"] < json["content_created_date"]:
raise UserError(
"content_updated_date cannot come before content_created_date"
Expand Down
8 changes: 4 additions & 4 deletions indexd/index/drivers/alchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ def to_document_dict(self):
content_created_date = (
self.content_created_date.isoformat()
if self.content_created_date is not None
else ""
else None
)
content_updated_date = (
self.content_updated_date.isoformat()
if self.content_created_date is not None
else ""
else None
)

return {
Expand Down Expand Up @@ -1250,11 +1250,11 @@ def update(self, did, rev, changing_fields):

create_urls_metadata(changing_fields["urls_metadata"], record, session)

if "content_created_date" in changing_fields:
if changing_fields.get("content_created_date") is not None:
record.content_created_date = datetime.datetime.fromisoformat(
changing_fields["content_created_date"]
)
if "content_updated_date" in changing_fields:
if changing_fields.get("content_updated_date") is not None:
if record.content_created_date is None:
raise UserError(
"Cannot set content_updated_date on record that does not have a content_created_date"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "indexd"
version = "3.5.0"
version = "5.0.0"
description = "Gen3 Indexing Service"
authors = ["CTDS UChicago <[email protected]>"]
license = "Apache-2.0"
Expand Down
19 changes: 19 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2676,6 +2676,25 @@ def test_changing_timestamps_updated_not_before_created(client, user):
assert update_obj_resp.status_code == 400


def test_changing_none_timestamps(client, user):
"""
Checks that updates with null values are handled correctly
"""
data = get_doc()
create_obj_resp = client.post("/index/", json=data, headers=user)
assert create_obj_resp.status_code == 200
obj_did = create_obj_resp.json["did"]
obj_rev = create_obj_resp.json["rev"]
update_json = {
"content_created_date": None,
"content_updated_date": None,
}
update_obj_resp = client.put(
f"/index/{obj_did}?rev={obj_rev}", json=update_json, headers=user
)
assert update_obj_resp.status_code == 200


def test_changing_timestamps_no_updated_without_created(client, user):
"""
Checks that records cannot be updated to have a content_updated_date when a content_created_date does not exist
Expand Down
8 changes: 4 additions & 4 deletions tests/test_drs.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ def test_timestamps_none(client, user):
obj_did = create_obj_resp.json["did"]
drs_resp = client.get(f"/ga4gh/drs/v1/objects/{obj_did}")
assert drs_resp.status_code == 200
assert drs_resp.json.get("created_time") == ""
assert drs_resp.json.get("updated_time") == ""
assert drs_resp.json.get("created_time") is None
assert drs_resp.json.get("updated_time") is None
record_resp = client.get(f"/index/{obj_did}")
assert record_resp.status_code == 200
assert record_resp.json.get("content_created_date") == ""
assert record_resp.json.get("content_updated_date") == ""
assert record_resp.json.get("content_created_date") is None
assert record_resp.json.get("content_updated_date") is None
assert drs_resp.json["index_created_time"] == record_resp.json["created_date"]
assert drs_resp.json["index_updated_time"] == record_resp.json["updated_date"]

Expand Down

0 comments on commit c6c8a73

Please sign in to comment.