Skip to content

[SQL] Fix az sql server update failing with "Invalid value given for parameter RetentionDays"#33593

Draft
Copilot wants to merge 2 commits into
devfrom
copilot/fix-invalid-retentiondays-error-again
Draft

[SQL] Fix az sql server update failing with "Invalid value given for parameter RetentionDays"#33593
Copilot wants to merge 2 commits into
devfrom
copilot/fix-invalid-retentiondays-error-again

Conversation

Copilot AI commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Related command
az sql server update

Description

az sql server update fails with Invalid value given for parameter RetentionDays even when --soft-delete-retention-days is not specified by the user. This affects any update operation on legacy servers (e.g., --enable-public-network true).

Root cause: The Azure SQL API returns retentionDays = -1 for servers where soft delete was never configured. On every PUT, the API now validates the server's internal retentionDays regardless of whether the field was included in the request body. A prior fix omitted the field (None) from the PUT body, but the API still reads the existing -1 from its internal state and rejects it.

Fix:

  • In server_update: when --soft-delete-retention-days is not provided and the existing instance.retention_days < 0, normalize to 0 (disabled) so the PUT body explicitly carries a valid value, migrating the legacy -1 state to 0
  • No behavior change for servers with retention_days of None, 0, or 1–7
# Before (broken): sets None → field omitted → API uses internal -1 → error
else:
    instance.retention_days = None

# After: normalize legacy -1 to 0 (disabled, valid for PUT)
elif instance.retention_days is not None and instance.retention_days < 0:
    instance.retention_days = 0

Testing Guide

Unit tests added in ServerUpdateRetentionDaysUnitTest (no live resources required):

# Run the new unit tests
python -m unittest azure.cli.command_modules.sql.tests.latest.test_sql_commands.ServerUpdateRetentionDaysUnitTest -v

To reproduce the fix manually on a legacy server:

az sql server update -g <resource_group> -n <server_name> --enable-public-network true
# Previously failed with: Invalid value given for parameter RetentionDays
# Now succeeds; retentionDays is normalized from -1 to 0 in the PUT request

History Notes

[SQL] az sql server update: Fix "Invalid value given for parameter RetentionDays" error on servers where soft delete retention was never configured


This checklist is used to make sure that common guidelines for a pull request are followed.

@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented Jun 21, 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 21, 2026

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

…er RetentionDays

When the Azure SQL API returns retention_days=-1 for legacy servers (where soft
delete was never configured), the server_update command was failing with
"Invalid value given for parameter RetentionDays" because:
1. The previous fix set instance.retention_days=None (omitting the field from PUT)
2. The Azure SQL API then internally used the existing -1 value and rejected it

Fix: normalize -1 to 0 (disabled) when user does not specify --soft-delete-retention-days.

Closes #32741
Copilot AI changed the title [WIP] Fix invalid value error for RetentionDays in az sql server update [SQL] Fix az sql server update failing with "Invalid value given for parameter RetentionDays" Jun 21, 2026
Copilot AI requested a review from a0x1ab June 21, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants