@@ -271,9 +271,18 @@ def get_prediction_job(
271
271
if tasks := job_settings .get ("tasks" , []):
272
272
cluster_response = _get_job_cluster (tasks , job_settings .get ("job_clusters" , []))
273
273
if cluster := cluster_response .result :
274
- prediction_cluster = _deep_update (
275
- cluster , prediction ["solutions" ][preference ]["configuration" ]
276
- )
274
+ # num_workers/autoscale are mutually exclusive settings, and we are relying on our Prediction
275
+ # Recommendations to set these appropriately. Since we may recommend a Static cluster (i.e. a cluster
276
+ # with `num_workers`) for a cluster that was originally autoscaled, we want to make sure to remove this
277
+ # prior configuration
278
+ if "num_workers" in cluster :
279
+ del cluster ["num_workers" ]
280
+
281
+ if "autoscale" in cluster :
282
+ del cluster ["autoscale" ]
283
+
284
+ prediction_cluster = _deep_update (cluster , prediction ["solutions" ][preference ]["configuration" ])
285
+
277
286
if cluster_key := tasks [0 ].get ("job_cluster_key" ):
278
287
job_settings ["job_clusters" ] = [
279
288
j
@@ -380,9 +389,20 @@ def run_job_object(job: dict) -> Response[str]:
380
389
381
390
if cluster := cluster_response .result :
382
391
if len (tasks ) == 1 :
392
+ # For `new_cluster` definitions, Databricks will automatically assign the newly created cluster a name,
393
+ # and will reject any run submissions where the `cluster_name` is pre-populated
394
+ if "cluster_name" in cluster :
395
+ del cluster ["cluster_name" ]
396
+
383
397
tasks [0 ]["new_cluster" ] = cluster
384
398
del tasks [0 ]["job_cluster_key" ]
385
399
else :
400
+ # If the original Job has a pre-existing Policy, we want to remove this from the `create_cluster` payload,
401
+ # since we are not allowed to create clusters with certain policies via that endpoint, e.g. we cannot
402
+ # create a `Job Compute` cluster via this endpoint.
403
+ if "policy_id" in cluster :
404
+ del cluster ["policy_id" ]
405
+
386
406
# Create an "All-Purpose Compute" cluster
387
407
cluster ["cluster_name" ] = cluster ["cluster_name" ] or job ["settings" ]["name" ]
388
408
cluster ["autotermination_minutes" ] = 10 # 10 minutes is the minimum
0 commit comments