fix(cli): protect against timeseries get_aspects (#7665)

This commit is contained in:
Harshal Sheth 2023-03-23 10:34:11 +05:30 committed by GitHub
parent f872ca9cba
commit 3b519924e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -25,6 +25,7 @@ concurrency:
jobs: jobs:
check_jars: check_jars:
strategy: strategy:
max-parallel: 1
fail-fast: false fail-fast: false
matrix: matrix:
command: command:

View File

@ -12,6 +12,7 @@ from requests.models import HTTPError
from datahub.cli.cli_utils import get_boolean_env_variable, get_url_and_token from datahub.cli.cli_utils import get_boolean_env_variable, get_url_and_token
from datahub.configuration.common import ConfigModel, GraphError, OperationalError from datahub.configuration.common import ConfigModel, GraphError, OperationalError
from datahub.emitter.aspect import TIMESERIES_ASPECT_MAP
from datahub.emitter.mce_builder import Aspect from datahub.emitter.mce_builder import Aspect
from datahub.emitter.rest_emitter import DatahubRestEmitter from datahub.emitter.rest_emitter import DatahubRestEmitter
from datahub.emitter.serialization_helper import post_json_transform from datahub.emitter.serialization_helper import post_json_transform
@ -131,10 +132,16 @@ class DataHubGraph(DatahubRestEmitter):
:param version: The version of the aspect to retrieve. The default of 0 means latest. Versions > 0 go from oldest to newest, so 1 is the oldest. :param version: The version of the aspect to retrieve. The default of 0 means latest. Versions > 0 go from oldest to newest, so 1 is the oldest.
:return: the Aspect as a dictionary if present, None if no aspect was found (HTTP status 404) :return: the Aspect as a dictionary if present, None if no aspect was found (HTTP status 404)
:raises TypeError: if the aspect type is a timeseries aspect
:raises HttpError: if the HTTP response is not a 200 or a 404 :raises HttpError: if the HTTP response is not a 200 or a 404
""" """
aspect = aspect_type.ASPECT_NAME aspect = aspect_type.ASPECT_NAME
if aspect in TIMESERIES_ASPECT_MAP:
raise TypeError(
'Cannot get a timeseries aspect using "get_aspect". Use "get_latest_timeseries_value" instead.'
)
url: str = f"{self._gms_server}/aspects/{Urn.url_encode(entity_urn)}?aspect={aspect}&version={version}" url: str = f"{self._gms_server}/aspects/{Urn.url_encode(entity_urn)}?aspect={aspect}&version={version}"
response = self._session.get(url) response = self._session.get(url)
if response.status_code == 404: if response.status_code == 404: