diff --git a/connect_ext_ppr/validator.py b/connect_ext_ppr/validator.py index fa1d79a..dcabe95 100644 --- a/connect_ext_ppr/validator.py +++ b/connect_ext_ppr/validator.py @@ -2,6 +2,7 @@ from fastapi import status from connect_ext_ppr.errors import ExtensionValidationError +from connect_ext_ppr.models.ppr import PPRVersion def validate_deployment(deployment, account_id): @@ -84,7 +85,7 @@ def validate_pricelist_ids(client, product_id, req_mp_configs, dep_mp_configs): }) -def validate_marketplaces_ppr(ppr, dr_marketplaces, dep_marketplaces): +def validate_marketplaces_ppr(ppr, dr_marketplaces, dep_marketplaces, db): """ Validates that we can apply the ppr to all marketplaces """ @@ -92,8 +93,10 @@ def validate_marketplaces_ppr(ppr, dr_marketplaces, dep_marketplaces): mkplcs_w_erros = [] for mp_data in dr_marketplaces: mp_id = mp_data.id - if dep_mkplc_map[mp_id].ppr_id and dep_mkplc_map[mp_id].ppr_id > ppr.id: - mkplcs_w_erros.append(mp_id) + if mp_ppr_id := dep_mkplc_map[mp_id].ppr_id: + mp_ppr = db.query(PPRVersion).filter_by(id=mp_ppr_id).first() + if mp_ppr.version > ppr.version: + mkplcs_w_erros.append(mp_id) if mkplcs_w_erros: raise ExtensionValidationError.VAL_004( diff --git a/connect_ext_ppr/webapp.py b/connect_ext_ppr/webapp.py index bec98d6..3a970a5 100644 --- a/connect_ext_ppr/webapp.py +++ b/connect_ext_ppr/webapp.py @@ -161,7 +161,7 @@ def add_dep_request( dr_marketplaces=deployment_request.marketplaces, dep_marketplaces=dep_marketplaces, ) - validate_marketplaces_ppr(ppr, deployment_request.marketplaces, dep_marketplaces) + validate_marketplaces_ppr(ppr, deployment_request.marketplaces, dep_marketplaces, db) instance = add_new_deployment_request( db, deployment_request, deployment, account_id, logger,