"""Module with functions that takes data from art_relation database.""" from oto import response from sqlalchemy.exc import SQLAlchemyError from label_copy_export.connectors import mysql from label_copy_export.connectors.sentry import sentry_client from label_copy_export.constants import models from label_copy_export.models.sql import distribution_format def get_distribution_format_name(product_id): """Get distribution_format_name from art_relations for release id. Args: product_id (str): product id. Returns: response.Response: containing dict of dict message dict keyed by product_id """ try: if not product_id: return response.Response(message={}) with mysql.ar_db_session_scope() as session: rows = session.execute( distribution_format .SELECT_DISPLAY_DISTRIBUTION_FORMAT_BY_PRODUCT_ID, {models.PRODUCT_ID: product_id}) result = rows.fetchone() if not result: return response.create_not_found_response() return response.Response(message=dict(result)) except SQLAlchemyError as e: if sentry_client: sentry_client.captureException() return response.create_fatal_response(e.args)