@@ -68,49 +68,62 @@ def estimate_cost(
68
68
portals = portals ,
69
69
)
70
70
adaptor_properties = adaptors .get_adaptor_properties (dataset )
71
- request_is_valid = check_request_validity (
72
- request = request ,
73
- mandatory_inputs = mandatory_inputs ,
74
- adaptor_properties = adaptor_properties ,
75
- )
76
71
costing_info = compute_costing (
77
72
request .get ("inputs" , {}), adaptor_properties , request_origin
78
73
)
79
74
cost = compute_highest_cost_limit_ratio (costing_info )
80
75
if costing_info .cost_bar_steps :
81
76
cost .cost_bar_steps = costing_info .cost_bar_steps
82
- costing_info .request_is_valid = request_is_valid
77
+ try :
78
+ check_request_validity (
79
+ request = request ,
80
+ request_origin = request_origin ,
81
+ mandatory_inputs = mandatory_inputs ,
82
+ adaptor_properties = adaptor_properties ,
83
+ )
84
+ except exceptions .InvalidRequest as exc :
85
+ cost .request_is_valid = False
86
+ cost .invalid_reason = exc .detail
83
87
return cost
84
88
85
89
86
90
def check_request_validity (
87
- request : dict [str , Any ], mandatory_inputs : bool , adaptor_properties : dict [str , Any ]
88
- ) -> bool :
91
+ request : dict [str , Any ],
92
+ request_origin : RequestOrigin ,
93
+ mandatory_inputs : bool ,
94
+ adaptor_properties : dict [str , Any ],
95
+ ) -> None :
89
96
"""
90
97
Check if the request is valid.
91
98
92
99
Parameters
93
100
----------
94
101
request : dict[str, Any]
95
102
Request to be processed.
103
+ request_origin : RequestOrigin
104
+ Origin of the request.
96
105
mandatory_inputs : bool
97
106
Whether mandatory inputs have been provided.
98
107
adaptor_properties : dict[str, Any]
99
108
Adaptor properties.
100
109
101
110
Returns
102
111
-------
103
- bool
104
- Whether the request is valid.
112
+ None
113
+
114
+ Raises
115
+ ------
116
+ exceptions.InvalidRequest
117
+ If the request is invalid.
105
118
"""
106
- if not mandatory_inputs :
107
- return False
119
+ if not mandatory_inputs and request_origin == RequestOrigin . ui :
120
+ raise exceptions . InvalidRequest ( "missing mandatory inputs" )
108
121
try :
109
122
adaptor = adaptors .instantiate_adaptor (adaptor_properties = adaptor_properties )
110
123
_ = adaptor .check_validity (request .get ("inputs" , {}))
111
- return True
112
- except cads_adaptors .exceptions .InvalidRequest :
113
- return False
124
+ return
125
+ except cads_adaptors .exceptions .InvalidRequest as exc :
126
+ raise exceptions . InvalidRequest ( str ( exc ))
114
127
115
128
116
129
def compute_highest_cost_limit_ratio (
@@ -173,7 +186,9 @@ def compute_costing(
173
186
)
174
187
costing_config : dict [str , Any ] = adaptor_properties ["config" ].get ("costing" , {})
175
188
limits : dict [str , Any ] = costing_config .get ("max_costs" , {})
176
- cost_bar_steps = costing_config .get ("cost_bar_steps" , None )
189
+ cost_bar_steps = (
190
+ costing_config .get ("cost_bar_steps" , None ) if request_origin == "ui" else None
191
+ )
177
192
costing_info = models .CostingInfo (
178
193
costs = costs , limits = limits , cost_bar_steps = cost_bar_steps
179
194
)
0 commit comments