"""Products Model.""" from owsresponse import response from sentry_sdk import capture_exception from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.sql import text from blacklist_manager.constants import error from blacklist_manager.models.sql.product_data import PRODUCT_DATA_SQL def fetch_product_details_by_id(product_id, session): """Get the data of products according to sql by id. Args: product_id (dict): Id of product to be validated for blacklisting. Returns: Response: Data of product. """ try: product = session.execute(text(PRODUCT_DATA_SQL), {'product_id': product_id}).fetchone() if not product: return response.create_not_found_response( message=error.PRODUCT_NOT_FOUND_MESSAGE.format(product_id)) return response.Response(message=product._asdict(), status=200) except SQLAlchemyError: capture_exception() return response.create_fatal_response()