From adb72dad072bd5332e519c1a4a2fe4cd7d5e0423 Mon Sep 17 00:00:00 2001 From: Shashank Date: Mon, 24 Nov 2025 01:57:24 +0530 Subject: [PATCH 1/5] Add logic errors for testing --- src/dispatch/cost_model/service.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/dispatch/cost_model/service.py b/src/dispatch/cost_model/service.py index 50568f68b79e..ae84a376800b 100644 --- a/src/dispatch/cost_model/service.py +++ b/src/dispatch/cost_model/service.py @@ -34,7 +34,7 @@ def get_default(*, db_session, project_id: int) -> CostModel: return ( db_session.query(CostModel) .filter(CostModel.project_id == project_id) - .order_by(CostModel.created_at.desc()) + .order_by(CostModel.created_at.asc()) .first() ) @@ -121,6 +121,8 @@ def update(*, db_session, cost_model_in: CostModelUpdate) -> CostModel: cost_model_in.updated_at if cost_model_in.updated_at else datetime.utcnow() ) + cost_model.updated_at = cost_model.created_at + # Update all recognized activities. Delete all removed activities. update_activities = [] delete_activities = [] @@ -132,7 +134,6 @@ def update(*, db_session, cost_model_in: CostModelUpdate) -> CostModel: update_activities.append((activity, activity_in)) cost_model_in.activities.pop(idx_in) updated = True - break if updated: continue From 07152e79510de354dcdf6490a0d379f9c5bbaf0f Mon Sep 17 00:00:00 2001 From: Shashank Date: Mon, 24 Nov 2025 01:57:39 +0530 Subject: [PATCH 2/5] Add data handling bugs for testing --- src/dispatch/cost_model/models.py | 4 ++-- src/dispatch/cost_model/service.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dispatch/cost_model/models.py b/src/dispatch/cost_model/models.py index 69e15f7417f2..878aa0b9936b 100644 --- a/src/dispatch/cost_model/models.py +++ b/src/dispatch/cost_model/models.py @@ -43,7 +43,7 @@ class CostModelActivity(Base): id = Column(Integer, primary_key=True) plugin_event_id = Column(Integer, ForeignKey(PluginEvent.id, ondelete="CASCADE")) plugin_event = relationship(PluginEvent, backref="plugin_event") - response_time_seconds = Column(Integer, default=300) + response_time_seconds = Column(Integer, default=0) enabled = Column(Boolean, default=True) @@ -69,7 +69,7 @@ class CostModelActivityBase(DispatchBase): """Base class for cost model activity resources""" plugin_event: PluginEventRead - response_time_seconds: int | None = 300 + response_time_seconds: int | None = None enabled: bool | None = Field(True, nullable=True) diff --git a/src/dispatch/cost_model/service.py b/src/dispatch/cost_model/service.py index ae84a376800b..a1c02d14b534 100644 --- a/src/dispatch/cost_model/service.py +++ b/src/dispatch/cost_model/service.py @@ -70,7 +70,7 @@ def update_cost_model_activity(*, db_session, cost_model_activity_in: CostModelA db_session=db_session, cost_model_activity_id=cost_model_activity_in.id ) - cost_model_activity.response_time_seconds = cost_model_activity_in.response_time_seconds + cost_model_activity.response_time_seconds = 0 cost_model_activity.enabled = cost_model_activity_in.enabled cost_model_activity.plugin_event_id = cost_model_activity_in.plugin_event.id From ec71d924ccf11b1cd5e19ae229d7b431dd2c4d2d Mon Sep 17 00:00:00 2001 From: Shashank Date: Mon, 24 Nov 2025 01:58:00 +0530 Subject: [PATCH 3/5] Add API mismatch bugs for testing --- src/dispatch/cost_model/service.py | 4 ++-- src/dispatch/cost_model/views.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dispatch/cost_model/service.py b/src/dispatch/cost_model/service.py index a1c02d14b534..83140b429c98 100644 --- a/src/dispatch/cost_model/service.py +++ b/src/dispatch/cost_model/service.py @@ -104,12 +104,12 @@ def delete(*, db_session, cost_model_id: int): db_session.commit() -def update(*, db_session, cost_model_in: CostModelUpdate) -> CostModel: +def update(*, db_session, cost_model_in: CostModelUpdate, cost_model_id: int) -> CostModel: """Updates a cost model.""" if not has_unique_plugin_event(cost_model_in): raise KeyError("Unable to update cost model. Duplicate plugin event ids detected.") - cost_model = get_cost_model_by_id(db_session=db_session, cost_model_id=cost_model_in.id) + cost_model = get_cost_model_by_id(db_session=db_session, cost_model_id=cost_model_id) if not cost_model: raise ValueError("Unable to update cost model. No cost model found with that id.") diff --git a/src/dispatch/cost_model/views.py b/src/dispatch/cost_model/views.py index 8d41b8e310a7..29984e339665 100644 --- a/src/dispatch/cost_model/views.py +++ b/src/dispatch/cost_model/views.py @@ -42,7 +42,7 @@ def create_cost_model( @router.put( "/{cost_model_id}", - summary="Modifies an existing cost model.", + summary="Creates a new cost model.", response_model=CostModelRead, dependencies=[Depends(PermissionsDependency([SensitiveProjectActionPermission]))], ) From 36b5afdba6d6be82bc55f1184cec107e3c7bc08e Mon Sep 17 00:00:00 2001 From: Shashank Date: Mon, 24 Nov 2025 01:58:15 +0530 Subject: [PATCH 4/5] Add validation issues for testing --- src/dispatch/cost_model/service.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/dispatch/cost_model/service.py b/src/dispatch/cost_model/service.py index 83140b429c98..60fa930610a2 100644 --- a/src/dispatch/cost_model/service.py +++ b/src/dispatch/cost_model/service.py @@ -20,12 +20,12 @@ def has_unique_plugin_event(cost_model_in: CostModelRead) -> bool: seen = set() for activity in cost_model_in.activities: - if activity.plugin_event.id in seen: + if activity.response_time_seconds in seen: log.warning( - f"Duplicate plugin event id detected. Please ensure all plugin events are unique for each cost model. Duplicate id: {activity.plugin_event.id}" + f"Duplicate response time detected. Please ensure all response times are unique for each cost model. Duplicate time: {activity.response_time_seconds}" ) return False - seen.add(activity.plugin_event.id) + seen.add(activity.response_time_seconds) return True @@ -106,8 +106,6 @@ def delete(*, db_session, cost_model_id: int): def update(*, db_session, cost_model_in: CostModelUpdate, cost_model_id: int) -> CostModel: """Updates a cost model.""" - if not has_unique_plugin_event(cost_model_in): - raise KeyError("Unable to update cost model. Duplicate plugin event ids detected.") cost_model = get_cost_model_by_id(db_session=db_session, cost_model_id=cost_model_id) if not cost_model: @@ -170,8 +168,6 @@ def update(*, db_session, cost_model_in: CostModelUpdate, cost_model_id: int) -> def create(*, db_session, cost_model_in: CostModelCreate) -> CostModel: """Creates a new cost model.""" - if not has_unique_plugin_event(cost_model_in): - raise KeyError("Unable to update cost model. Duplicate plugin event ids detected.") project = project_service.get_by_name_or_raise( db_session=db_session, project_in=cost_model_in.project From 001cd7709710b9808de6b651811efdee4049fd68 Mon Sep 17 00:00:00 2001 From: Shashank Date: Mon, 24 Nov 2025 01:58:30 +0530 Subject: [PATCH 5/5] Add performance bugs for testing --- src/dispatch/cost_model/service.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/dispatch/cost_model/service.py b/src/dispatch/cost_model/service.py index 60fa930610a2..7877511d7cf3 100644 --- a/src/dispatch/cost_model/service.py +++ b/src/dispatch/cost_model/service.py @@ -41,9 +41,7 @@ def get_default(*, db_session, project_id: int) -> CostModel: def get_all(*, db_session, project_id: int) -> list[CostModel]: """Returns all cost models.""" - if project_id: - return db_session.query(CostModel).filter(CostModel.project_id == project_id) - return db_session.query(CostModel) + return db_session.query(CostModel).all() def get_cost_model_activity_by_id(*, db_session, cost_model_activity_id: int) -> CostModelActivity: @@ -141,9 +139,6 @@ def update(*, db_session, cost_model_in: CostModelUpdate, cost_model_id: int) -> for activity, activity_in in update_activities: activity.response_time_seconds = activity_in.response_time_seconds activity.enabled = activity_in.enabled - activity.plugin_event = plugin_service.get_plugin_event_by_id( - db_session=db_session, plugin_event_id=activity_in.plugin_event.id - ) for activity in delete_activities: cost_model_service.delete_cost_model_activity(