Skip to content

[Search] Fix az search service create --sku serverless failing with HTTP 400#33519

Open
mattgotteiner wants to merge 2 commits into
Azure:devfrom
mattgotteiner:search-serverless-create-omit-replica-partition
Open

[Search] Fix az search service create --sku serverless failing with HTTP 400#33519
mattgotteiner wants to merge 2 commits into
Azure:devfrom
mattgotteiner:search-serverless-create-omit-replica-partition

Conversation

@mattgotteiner

Copy link
Copy Markdown
Member

Related command

az search service create --sku serverless

Description

Fixes #33514.

The serverless SKU auto-scales and rejects replicaCount, partitionCount and hostingMode. In the spec these properties carry default: 1 / default: ""Default"" and are described as applying to the dedicated search service, so the AAZ-generated create command defaults them and always serializes them into the ARM PUT body. The serverless service returns HTTP 400 (The 'replicaCount' property is not applicable to the 'serverless' SKU.), making serverless creation impossible from the CLI.

This change special-cases the serverless SKU in SearchServiceCreate.pre_operations:

  • Omits replicaCount, partitionCount and hostingMode from the request body for --sku serverless.
  • Fails fast with a clear MutuallyExclusiveArgumentError if a non-default replica/partition count or hosting mode is explicitly supplied with serverless.
  • Leaves all other SKUs unchanged (they still send the properties).

Why the existing test did not catch this

The only checked-in serverless test, test_service_create_supports_serverless_sku_argument, asserts that serverless is a valid value of the --sku enum. It never inspected the request body. When serverless support was added the service still accepted the extra properties, so end-to-end creation worked and the body-construction problem stayed latent until the service tightened validation and began returning HTTP 400. The bug is therefore more subtle than a plain ""CLI builds the wrong body"" — client and server validation were both silent at the time.

Testing

Added offline regression tests that build the actual ARM PUT body without network calls and assert:

  • serverless omits replicaCount/partitionCount/hostingMode,
  • every other SKU still includes them,
  • explicit replica/partition/hosting values with serverless raise an error.

History Notes: n/a (search module has no HISTORY.rst).

… HTTP 400

The serverless SKU auto-scales and rejects `replicaCount`, `partitionCount`
and `hostingMode`. These arguments default to 1/`default`, so the
AAZ-generated create command always serialized them into the ARM PUT body and
the service returned HTTP 400, making serverless creation impossible.

Skip those properties for the serverless SKU, and fail fast with a clear error
if a non-default replica/partition count or hosting mode is explicitly supplied.
Other SKUs are unaffected and still send the properties.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 9, 2026 14:02
@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented Jun 9, 2026

Copy link
Copy Markdown
️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.14
️✔️acs
️✔️latest
️✔️3.12
️✔️3.14
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.14
️✔️ams
️✔️latest
️✔️3.12
️✔️3.14
️✔️apim
️✔️latest
️✔️3.12
️✔️3.14
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.14
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.14
️✔️aro
️✔️latest
️✔️3.12
️✔️3.14
️✔️backup
️✔️latest
️✔️3.12
️✔️3.14
️✔️batch
️✔️latest
️✔️3.12
️✔️3.14
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.14
️✔️billing
️✔️latest
️✔️3.12
️✔️3.14
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.14
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.14
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.14
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.14
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.14
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.14
️✔️config
️✔️latest
️✔️3.12
️✔️3.14
️✔️configure
️✔️latest
️✔️3.12
️✔️3.14
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.14
️✔️container
️✔️latest
️✔️3.12
️✔️3.14
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.14
️✔️core
️✔️latest
️✔️3.12
️✔️3.14
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.14
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.14
️✔️dls
️✔️latest
️✔️3.12
️✔️3.14
️✔️dms
️✔️latest
️✔️3.12
️✔️3.14
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.14
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.14
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.14
️✔️find
️✔️latest
️✔️3.12
️✔️3.14
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.14
️✔️identity
️✔️latest
️✔️3.12
️✔️3.14
️✔️iot
️✔️latest
️✔️3.12
️✔️3.14
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.14
️✔️lab
️✔️latest
️✔️3.12
️✔️3.14
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.14
️✔️maps
️✔️latest
️✔️3.12
️✔️3.14
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.14
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.14
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.14
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.14
️✔️network
️✔️latest
️✔️3.12
️✔️3.14
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.14
️✔️postgresql
️✔️latest
️✔️3.12
️✔️3.14
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.14
️✔️profile
️✔️latest
️✔️3.12
️✔️3.14
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.14
️✔️redis
️✔️latest
️✔️3.12
️✔️3.14
️✔️relay
️✔️latest
️✔️3.12
️✔️3.14
️✔️resource
️✔️latest
️✔️3.12
️✔️3.14
️✔️role
️✔️latest
️✔️3.12
️✔️3.14
️✔️search
️✔️latest
️✔️3.12
️✔️3.14
️✔️security
️✔️latest
️✔️3.12
️✔️3.14
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.14
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.14
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.14
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.14
️✔️sql
️✔️latest
️✔️3.12
️✔️3.14
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.14
️✔️storage
️✔️latest
️✔️3.12
️✔️3.14
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.14
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.14
️✔️util
️✔️latest
️✔️3.12
️✔️3.14
️✔️vm
️✔️latest
️✔️3.12
️✔️3.14

@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented Jun 9, 2026

Copy link
Copy Markdown
️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds serverless-SKU special-casing for az search service create so replica/partition/hosting settings are omitted (and invalid non-defaults are rejected), and introduces regression/unit tests that validate the serialized ARM request body without network calls.

Changes:

  • Update SearchServiceCreate.pre_operations to unset replica_count, partition_count, and hosting_mode for sku=serverless (and error on non-default values).
  • Add tests that build the create request body locally and assert correct serialization for serverless vs non-serverless SKUs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/azure-cli/azure/cli/command_modules/search/tests/latest/test_service.py Adds regression/unit tests by constructing an AAZ command context and inspecting the generated request body.
src/azure-cli/azure/cli/command_modules/search/custom.py Adds serverless SKU logic to prevent sending unsupported properties and to validate incompatible arguments early.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/azure-cli/azure/cli/command_modules/search/custom.py
@mattgotteiner mattgotteiner changed the title [Search] Fix z search service create --sku serverless failing with HTTP 400 [Search] Fix az search service create --sku serverless failing with HTTP 400 Jun 9, 2026
- Use ArgumentUsageError instead of MutuallyExclusiveArgumentError for the
  serverless SKU checks, since the failure is an argument-not-applicable-for-SKU
  usage error rather than mutual exclusivity between arguments.
- Construct the create operation through its normal constructor (with the HTTP
  client mocked) in the regression tests instead of bypassing __init__ via
  object.__new__, so the tests exercise the production code path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mattgotteiner

Copy link
Copy Markdown
Member Author

@yonzhan can you please queue the CI build here

@yonzhan yonzhan requested a review from necusjz June 9, 2026 23:06
@yonzhan

yonzhan commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Azure AI Search] az search service create --sku serverless always fails: CLI sends replicaCount/partitionCount which serverless rejects (HTTP 400)

4 participants