From f9347490f1d4aa964cf0a4961a653d53cda841ab Mon Sep 17 00:00:00 2001 From: VineetBala-AOT Date: Tue, 9 Jan 2024 16:50:31 -0800 Subject: [PATCH] fixing linting for analytics --- analytics-api/src/analytics_api/config.py | 13 +++++++------ .../models/request_type_option.py | 18 +++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/analytics-api/src/analytics_api/config.py b/analytics-api/src/analytics_api/config.py index 115518b40..ba931c0a1 100644 --- a/analytics-api/src/analytics_api/config.py +++ b/analytics-api/src/analytics_api/config.py @@ -22,13 +22,14 @@ import os import sys +from typing import Union from dotenv import find_dotenv, load_dotenv # this will load all the envars from a .env file located in the project root (api) load_dotenv(find_dotenv()) -def get_named_config(environment: str | None) -> '_Config': +def get_named_config(environment: Union[str, None]) -> '_Config': """ Retrieve a configuration object by name. Used by the Flask app factory. @@ -38,16 +39,16 @@ def get_named_config(environment: str | None) -> '_Config': """ config_mapping = { 'development': DevConfig, - 'default': ProdConfig, - 'staging': ProdConfig, + 'default': ProdConfig, + 'staging': ProdConfig, 'production': ProdConfig, - 'testing': TestConfig, + 'testing': TestConfig, } try: print(f'Loading configuration: {environment}...') return config_mapping[environment]() - except KeyError: - raise KeyError(f'Configuration "{environment}" not found.') + except KeyError as e: + raise KeyError(f'Configuration "{environment}" not found.') from e class _Config(): # pylint: disable=too-few-public-methods diff --git a/analytics-api/src/analytics_api/models/request_type_option.py b/analytics-api/src/analytics_api/models/request_type_option.py index 50ad9775e..499291d11 100644 --- a/analytics-api/src/analytics_api/models/request_type_option.py +++ b/analytics-api/src/analytics_api/models/request_type_option.py @@ -94,16 +94,16 @@ def get_survey_result( return survey_result.all() # Check if there are records in survey_response before executing the final query which fetches reponses # even if the available_response table is not yet populated. - elif survey_response_exists: + if survey_response_exists: survey_result = (db.session.query((survey_question.c.position).label('position'), - (survey_question.c.label).label('question'), - func.json_agg(func.json_build_object('value', - survey_response.c.value, - 'count', - survey_response.c.response)) - .label('result')) - .join(survey_response, survey_response.c.request_key == survey_question.c.key) - .group_by(survey_question.c.position, survey_question.c.label)) + (survey_question.c.label).label('question'), + func.json_agg(func.json_build_object('value', + survey_response.c.value, + 'count', + survey_response.c.response)) + .label('result')) + .join(survey_response, survey_response.c.request_key == survey_question.c.key) + .group_by(survey_question.c.position, survey_question.c.label)) return survey_result.all()