From d68f1f48a20d8d128dab34449900762996db5aeb Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Thu, 19 Nov 2026 14:27:38 +0000 Subject: [PATCH 1/2] acc: make dms recreate tests independent of DMS write coalescing The operation buffer merges a write still waiting to be sent into the next one for the same resource, so a recreate's PENDING drop write is either sent on its own (two PATCHes, sequence_id 0 and 1) or merged into the save/failure (one PATCH at sequence_id 0), depending on timing. Fold the PENDING write and drop operation sequence_ids in these two tests so both outcomes print the same. aws: TestAccept/bundle/dms/successful-recreate Co-authored-by: Isaac --- acceptance/bin/print_requests.py | 45 +++++++++++++++++++ .../bundle/dms/failed-recreate/output.txt | 15 +------ acceptance/bundle/dms/failed-recreate/script | 4 +- .../bundle/dms/successful-recreate/output.txt | 15 +------ .../bundle/dms/successful-recreate/script | 5 ++- 5 files changed, 53 insertions(+), 31 deletions(-) diff --git a/acceptance/bin/print_requests.py b/acceptance/bin/print_requests.py index dda0476d4fd..868d3470001 100755 --- a/acceptance/bin/print_requests.py +++ b/acceptance/bin/print_requests.py @@ -224,6 +224,42 @@ def del_path(body, field): body.pop(leaf, None) +def fold_pending_operation_writes(requests): + """Drop a deployment-history PATCH that marks an operation PENDING when a later PATCH to + the same operation follows, and drop sequence_id from every operation PATCH. + + A recreate writes an operation twice: the drop marks it PENDING, the save (or failure) + finishes it. The CLI uploads writes in the background and merges a write still waiting + to be sent into the next one for the same resource, so depending on timing the service + gets one PATCH at sequence_id 0 or two at 0 and 1. Folding makes both read the same. + + >>> pending = {"method": "PATCH", "path": "/v/1/operations/a", "body": {"sequence_id": 0, "status": "OPERATION_STATUS_PENDING"}} + >>> done = {"method": "PATCH", "path": "/v/1/operations/a", "body": {"sequence_id": 1, "status": "OPERATION_STATUS_SUCCEEDED"}} + >>> merged = {"method": "PATCH", "path": "/v/1/operations/a", "body": {"sequence_id": 0, "status": "OPERATION_STATUS_SUCCEEDED"}} + >>> fold_pending_operation_writes([pending, done]) == fold_pending_operation_writes([merged]) + True + >>> fold_pending_operation_writes([pending, done]) + [{'method': 'PATCH', 'path': '/v/1/operations/a', 'body': {'status': 'OPERATION_STATUS_SUCCEEDED'}}] + >>> fold_pending_operation_writes([pending]) + [{'method': 'PATCH', 'path': '/v/1/operations/a', 'body': {'status': 'OPERATION_STATUS_PENDING'}}] + """ + + def is_operation_patch(req): + return req.get("method") == "PATCH" and "/operations/" in req.get("path", "") + + result = [] + for i, req in enumerate(requests): + if not is_operation_patch(req): + result.append(req) + continue + body = req.get("body") or {} + if body.get("status") == "OPERATION_STATUS_PENDING" and any( + is_operation_patch(r) and r["path"] == req["path"] for r in requests[i + 1 :] + ): + continue + result.append(dict(req, body={k: v for k, v in body.items() if k != "sequence_id"})) + return result + def main(): parser = argparse.ArgumentParser() parser.add_argument("path_filters", nargs="*", help="Path substring filters") @@ -274,6 +310,13 @@ def main(): "bodies, so a test asserts the same requests whether or not deployment history " "recording is on. Shorthand for the --del-body fields it implies.", ) + parser.add_argument( + "--fold-pending", + action="store_true", + help="Fold the PENDING write of a recreated resource into the write that finishes it, and " + "drop operation sequence_ids, so a test reads the same whether or not the CLI merged them. " + "See fold_pending_operation_writes.", + ) parser.add_argument("--fname", default=os.environ["OUT_REQUESTS"]) args = parser.parse_args() @@ -302,6 +345,8 @@ def main(): filtered_requests = filter_requests( requests, args.path_filters, args.get, args.sort, args.unique, args.method, args.dms ) + if args.fold_pending: + filtered_requests = fold_pending_operation_writes(filtered_requests) for req in filtered_requests: body = req.get("body") diff --git a/acceptance/bundle/dms/failed-recreate/output.txt b/acceptance/bundle/dms/failed-recreate/output.txt index c2f8ff329db..188c2b9eb65 100644 --- a/acceptance/bundle/dms/failed-recreate/output.txt +++ b/acceptance/bundle/dms/failed-recreate/output.txt @@ -131,7 +131,7 @@ API message: Fault injected by test. Files: 2 uploaded, 0 deleted ->>> print_requests.py --dms //api/2.0/bundle +>>> print_requests.py --dms --fold-pending //api/2.0/bundle { "method": "POST", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions", @@ -150,18 +150,6 @@ Files: 2 uploaded, 0 deleted "version_type": "VERSION_TYPE_DEPLOY" } } -{ - "method": "PATCH", - "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/2/operations/schemas.foo", - "q": { - "update_mask": "state,error_message,status" - }, - "body": { - "error_message": "", - "sequence_id": 0, - "status": "OPERATION_STATUS_PENDING" - } -} { "method": "PATCH", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/2/operations/schemas.foo", @@ -170,7 +158,6 @@ Files: 2 uploaded, 0 deleted }, "body": { "error_message": "Fault injected by test. (400 INVALID_PARAMETER_VALUE)", - "sequence_id": 1, "status": "OPERATION_STATUS_FAILED" } } diff --git a/acceptance/bundle/dms/failed-recreate/script b/acceptance/bundle/dms/failed-recreate/script index 45d790615da..a7f58603b50 100644 --- a/acceptance/bundle/dms/failed-recreate/script +++ b/acceptance/bundle/dms/failed-recreate/script @@ -25,7 +25,9 @@ trace update_file.py databricks.yml "catalog_name: main" "catalog_name: ${other_ trace fault.py "POST /api/2.1/unity-catalog/schemas" 400 0 1 INVALID_PARAMETER_VALUE trace musterr $CLI bundle deploy --auto-approve # Not sorted: the point of this test is the order the operations are recorded in. -trace print_requests.py --dms //api/2.0/bundle +# --fold-pending: the CLI merges the delete's PENDING write into the failure if it has not been +# sent yet, so the failure is the one write that always reaches the service. +trace print_requests.py --dms --fold-pending //api/2.0/bundle title "The resource is not listed: state is what projects a resource, and the failed recreate left none" deployment_id=$(MSYS_NO_PATHCONV=1 $CLI workspace get-status "/Workspace/Users/${CURRENT_USER_NAME}/.bundle/dms-failed-recreate-${UNIQUE_NAME}/default/state/resources.deployment.json" | python3 -c 'import sys, json; print(json.load(sys.stdin)["object_id"])') diff --git a/acceptance/bundle/dms/successful-recreate/output.txt b/acceptance/bundle/dms/successful-recreate/output.txt index 225bea93a80..fb6e5980e30 100644 --- a/acceptance/bundle/dms/successful-recreate/output.txt +++ b/acceptance/bundle/dms/successful-recreate/output.txt @@ -124,7 +124,7 @@ Recreated schemas.foo Files: 2 uploaded, 0 deleted Resources: 1 created, 0 changed, 1 deleted, 0 unchanged ->>> print_requests.py --dms //api/2.0/bundle +>>> print_requests.py --dms --fold-pending //api/2.0/bundle { "method": "POST", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions", @@ -143,18 +143,6 @@ Resources: 1 created, 0 changed, 1 deleted, 0 unchanged "version_type": "VERSION_TYPE_DEPLOY" } } -{ - "method": "PATCH", - "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/2/operations/schemas.foo", - "q": { - "update_mask": "state,error_message,status" - }, - "body": { - "error_message": "", - "sequence_id": 0, - "status": "OPERATION_STATUS_PENDING" - } -} { "method": "PATCH", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/2/operations/schemas.foo", @@ -164,7 +152,6 @@ Resources: 1 created, 0 changed, 1 deleted, 0 unchanged "body": { "error_message": "", "resource_id": "dms_other_[UNIQUE_NAME].dms_successful_recreate_schema_[UNIQUE_NAME]", - "sequence_id": 1, "state": "{\"state\":{\"catalog_name\":\"dms_other_[UNIQUE_NAME]\",\"comment\":\"v1\",\"name\":\"dms_successful_recreate_schema_[UNIQUE_NAME]\",\"schema_id\":\"[UUID][2]\"}}", "status": "OPERATION_STATUS_SUCCEEDED" } diff --git a/acceptance/bundle/dms/successful-recreate/script b/acceptance/bundle/dms/successful-recreate/script index 87bdc98bc34..fd1ed7e5907 100644 --- a/acceptance/bundle/dms/successful-recreate/script +++ b/acceptance/bundle/dms/successful-recreate/script @@ -17,14 +17,15 @@ trace print_state.py --no-dms title "Recreate writes state twice - the entry is dropped, then the new resource is saved" # One operation per resource per version; both writes land on the same one. -# The drop opens it IN_PROGRESS, the save patches it to SUCCEEDED. +# The drop marks it PENDING, the save patches it to SUCCEEDED. The CLI merges the drop into the +# save if the drop has not been sent yet, so --fold-pending prints the same either way. # Unity Catalog has no catalog called "other", so make one to move the schema into. other_catalog="dms_other_${UNIQUE_NAME}" $CLI catalogs create "$other_catalog" &> LOG.catalog trap '$CLI catalogs delete "$other_catalog" --force >> LOG.catalog 2>&1' EXIT trace update_file.py databricks.yml "catalog_name: main" "catalog_name: ${other_catalog}" trace $CLI bundle deploy --auto-approve -trace print_requests.py --dms //api/2.0/bundle +trace print_requests.py --dms --fold-pending //api/2.0/bundle title "The recreate is done: nothing left to plan, and the serial moved to 2" dms_plan From 2444e08935256dc1cdf6f489b47108612fc36fcd Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Thu, 19 Nov 2026 14:27:56 +0000 Subject: [PATCH 2/2] acc: ruff format print_requests.py aws: TestAccept/bundle/dms/successful-recreate Co-authored-by: Isaac --- acceptance/bin/print_requests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/acceptance/bin/print_requests.py b/acceptance/bin/print_requests.py index 868d3470001..f23b4211bbd 100755 --- a/acceptance/bin/print_requests.py +++ b/acceptance/bin/print_requests.py @@ -260,6 +260,7 @@ def is_operation_patch(req): result.append(dict(req, body={k: v for k, v in body.items() if k != "sequence_id"})) return result + def main(): parser = argparse.ArgumentParser() parser.add_argument("path_filters", nargs="*", help="Path substring filters")