From 72ce7a45d06091966e0f19d1ca3004bcbc285b58 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Tue, 28 Jan 2025 09:35:03 -0300 Subject: [PATCH] fix backend response (#934) * fix backend response * more fixes * update basedosdados to b27 --- pipelines/datasets/cross_update/utils.py | 6 ++---- pipelines/utils/dump_to_gcs/tasks.py | 6 +++--- pipelines/utils/metadata/utils.py | 14 +++++++------- poetry.lock | 8 ++++---- pyproject.toml | 2 +- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/pipelines/datasets/cross_update/utils.py b/pipelines/datasets/cross_update/utils.py index 76c3bb484..33ef3121f 100644 --- a/pipelines/datasets/cross_update/utils.py +++ b/pipelines/datasets/cross_update/utils.py @@ -74,8 +74,7 @@ def find_closed_tables(backend: Backend): } }""" - response = backend._execute_query(query=query) - response = backend._simplify_response(response)["allCoverage"] + response = backend._execute_query(query=query)["allCoverage"]["items"] data = json_normalize(response) open_tables = data["table._id"].tolist() @@ -104,8 +103,7 @@ def find_closed_tables(backend: Backend): } }""" - response = backend._execute_query(query=query) - response = backend._simplify_response(response)["allCoverage"] + response = backend._execute_query(query=query)["allCoverage"]["items"] data = json_normalize(response) closed_tables = data["table._id"].tolist() diff --git a/pipelines/utils/dump_to_gcs/tasks.py b/pipelines/utils/dump_to_gcs/tasks.py index ec16cd11e..3d4a4164e 100644 --- a/pipelines/utils/dump_to_gcs/tasks.py +++ b/pipelines/utils/dump_to_gcs/tasks.py @@ -115,11 +115,11 @@ def download_data_to_gcs( # pylint: disable=R0912,R0913,R0914,R0915 """ log(query) data = b._execute_query(query_graphql, {'table_id' : table_id}) - nodes = data['allTable']['edges'] - if nodes == []: + nodes = data['allTable']['items'] + if len(nodes) == 0: return None - num_bytes = nodes[0]['node']['uncompressedFileSize'] + num_bytes = nodes[0]['uncompressedFileSize'] url_path = get_credentials_from_secret('url_download_data') secret_path_url_free = url_path['URL_DOWNLOAD_OPEN'] diff --git a/pipelines/utils/metadata/utils.py b/pipelines/utils/metadata/utils.py index 2634d1666..37600c3ce 100644 --- a/pipelines/utils/metadata/utils.py +++ b/pipelines/utils/metadata/utils.py @@ -146,7 +146,7 @@ def get_id( variables = dict(zip(keys, values)) response = backend._execute_query(query, variables=variables) - nodes = response[query_class]['edges'] + nodes = response[query_class]['items'] if len(nodes)>1: raise ValueError(f'More than 1 node was found in this query. Plese give query parameters that retrieve only one object. \nQuery:\n\t{query}\nVariables:{variables} \nNodes found:{nodes}') @@ -154,7 +154,7 @@ def get_id( if len(nodes) == 0: return response, None - id = nodes[0]['node']['_id'] + id = nodes[0]['_id'] return response, id @@ -171,14 +171,14 @@ def get_table_status(table_id:str, backend: bd.Backend) -> str: } } """ - response = backend._execute_query(query,{"table_id": table_id}) + response = backend._execute_query(query, {"table_id": table_id}) - nodes = response['allTable']['edges'] + nodes = response['allTable']['items'] - if nodes == []: + if len(nodes) == 0: return None - return nodes[0]['node']['status']['slug'] + return nodes[0]['status']['slug'] def extract_last_date_from_bq( dataset_id: str, @@ -708,7 +708,7 @@ def get_api_last_update_date(dataset_id: str, table_id: str, backend: bd.Backend """ variables = {"table_Id": django_table_id} response = backend._execute_query(query, variables) - clean_response = response['allUpdate']['edges'][0]['node']['latest'] + clean_response = response['allUpdate']['items'][0]['latest'] date_result = (datetime.strptime(clean_response[:10],"%Y-%m-%d")).date() return date_result diff --git a/poetry.lock b/poetry.lock index 8c62f2749..4cc512240 100644 --- a/poetry.lock +++ b/poetry.lock @@ -247,13 +247,13 @@ files = [ [[package]] name = "basedosdados" -version = "2.0.0b26" +version = "2.0.0b27" description = "Organizar e facilitar o acesso a dados brasileiros através de tabelas públicas no BigQuery." optional = false python-versions = "<4,>=3.9" files = [ - {file = "basedosdados-2.0.0b26-py3-none-any.whl", hash = "sha256:49356b5402ce6622750615687a442ca16517dc8f856bda264b9dfd1a8092c958"}, - {file = "basedosdados-2.0.0b26.tar.gz", hash = "sha256:ddb73added39ac0bdad0fdaecb282a6ddc904c8f1f8fbfde9e3be48d0858461b"}, + {file = "basedosdados-2.0.0b27-py3-none-any.whl", hash = "sha256:ad2ed3868e5a0e00835d417f6a99ae25f884c43683f2016c4e615ef8cfdef801"}, + {file = "basedosdados-2.0.0b27.tar.gz", hash = "sha256:f1b4df7248899b6757af9dab358333edc093b93ee4bef96eec1363e148225eb6"}, ] [package.dependencies] @@ -5580,4 +5580,4 @@ heapdict = "*" [metadata] lock-version = "2.0" python-versions = ">=3.10,<3.11" -content-hash = "dc24520a262709e84e08da4dfff76b86ab93bfe6477b19f8f6c0e93be1f42215" +content-hash = "d787078cf0031855679a68b2d0c78030df319c2891344ca863e88a5b9098131f" diff --git a/pyproject.toml b/pyproject.toml index 813aff1d4..5b4f7a70a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ Jinja2 = "3.0.3" MarkupSafe = "2.0.1" PyYAML = "6.0" Unidecode = "^1.3.4" -basedosdados = {version = "2.0.0b26", extras = ["all"]} +basedosdados = {version = "2.0.0b27", extras = ["all"]} beautifulsoup4 = "4.11.1" cachetools = "4.2.4" certifi = "2021.10.8"