Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

last valid bugfix/resuable migration tweak #134

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions scripts/migrations/maintainer.MD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: capitalized .MD suffix feels aggressive - this documentation has a degree! 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man i really flipped that caps nomenclature for no reason

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
As of this writing, migration #3 is safe to run any time you need
to regenerate the table column type data/data package cache (i.e.
if things are deleted, or in response to bugs in this process).
You should run the appropriate crawler first.
33 changes: 16 additions & 17 deletions scripts/migrations/migration.003.data_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ def get_s3_json_as_dict(bucket, key: str):
"""reads a json object as dict (typically metadata in this case)"""
s3_client = boto3.client("s3")
bytes_buffer = io.BytesIO()
print(bucket)
print(key)
s3_client.download_fileobj(
Bucket=bucket,
Key=key,
Expand All @@ -136,23 +134,24 @@ def cache_api_data(s3_bucket_name: str, db: str) -> None:
)
dp_details = []
for dp in list(data_packages):
dp_detail = {
"study": dp.split("__", 1)[0],
"name": dp.split("__", 1)[1],
}
try:
versions = column_types[dp_detail["study"]][dp_detail["name"]]
for version in versions:
dp_details.append(
{
**dp_detail,
**versions[version],
"version": version,
"id": dp + "__" + version,
}
)
except KeyError:
study, name, version = dp.split("__")
except ValueError:
print("invalid name: ", dp)
continue
try:
matching_col_types = column_types[study][name]
dp_details.append(
{
"study": study,
"name": name,
"version": version,
**matching_col_types[dp],
"id": dp,
}
)
except KeyError as e:
print("invalid key: ", e)
s3_client.put_object(
Bucket=s3_bucket_name,
Key=f"{BucketPath.CACHE.value}/{JsonFilename.DATA_PACKAGES.value}.json",
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/dashboard/get_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_csv_list_handler(event, context):
del context
s3_bucket_name = os.environ.get("BUCKET_NAME")
s3_client = boto3.client("s3")
if event["path"].startswith("/last_valid"):
if event["path"].startswith("/last-valid"):
key_prefix = "last_valid"
url_prefix = "last_valid"
elif event["path"].startswith("/aggregates"):
Expand Down
4 changes: 2 additions & 2 deletions tests/dashboard/test_get_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_get_csv(mock_bucket, params, status, expected):
does_not_raise(),
),
(
"/last_valid",
"/last-valid",
200,
[
"last_valid/study/encounter/princeton_plainsboro_teaching_hospital/099/study__encounter__aggregate.csv"
Expand All @@ -138,7 +138,7 @@ def test_get_csv(mock_bucket, params, status, expected):
@mock.patch.dict(os.environ, mock_utils.MOCK_ENV)
def test_get_csv_list(mock_bucket, path, status, expected, raises):
with raises:
if path.startswith("/last_valid"):
if path.startswith("/last-valid"):
_mock_last_valid()
event = {"path": path}
res = get_csv.get_csv_list_handler(event, {})
Expand Down
Loading