Skip to content

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

Draft
Copilot wants to merge 2 commits intodevfrom
copilot/fix-invalid-retentiondays-error
Draft

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

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

Related command
az sql server update

Description

az sql server update started failing with Invalid value given for parameter RetentionDays (value: -1) for servers created before the soft-delete feature existed, even when --soft-delete-retention-days was never specified. The Azure SQL API recently tightened validation to reject -1 (the legacy "not configured" sentinel) even when the field is omitted from the PUT body — the API validates the stored value.

  • sql/custom.pyserver_update(): When --soft-delete-retention-days is not specified and the server's existing retention_days is negative (i.e., the legacy -1 "not configured" value), explicitly set it to 0 (disabled) before the PUT. Valid existing values (0–7) and None continue to be omitted as before.
if soft_delete_retention_days is not None:
    instance.retention_days = soft_delete_retention_days
elif instance.retention_days is not None and instance.retention_days < 0:
    # Legacy -1 is now rejected by the API; map to 0 (disabled)
    instance.retention_days = 0
else:
    instance.retention_days = None
  • tests/latest/test_sql_commands.py: Added SqlServerUpdateRetentionDaysUnitTest with four unit tests covering: negative→0 conversion, valid value cleared when unspecified, explicit arg overrides existing, and explicit 0 disables soft delete.

Testing Guide

# Repro: server with legacy retention_days=-1 — previously failed
az sql server update -g <rg> -n <server> --enable-public-network true

# Unit tests (no live resources needed)
python -m unittest azure.cli.command_modules.sql.tests.latest.test_sql_commands.SqlServerUpdateRetentionDaysUnitTest -v

History Notes

[SQL] az sql server update: Fix "Invalid value given for parameter RetentionDays" error when updating servers with legacy retentionDays=-1


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

@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd Bot commented May 5, 2026

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

@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd Bot commented May 5, 2026

️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

When servers have retention_days=-1 (legacy 'not configured' value),
az sql server update fails because the API now validates this field
even when absent from the PUT body. Fix by explicitly setting it to 0
(disabled) when the existing value is negative and no --soft-delete-retention-days
argument is specified.

Add unit tests for the fix.

Agent-Logs-Url: https://github.com/Azure/azure-cli/sessions/15743958-26bc-49c2-92fa-8889d09d2b71

Co-authored-by: a0x1ab <59631311+a0x1ab@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix invalid value given for parameter RetentionDays in az sql server update [SQL] Fix az sql server update failing with "Invalid value given for parameter RetentionDays" May 5, 2026
Copilot finished work on behalf of a0x1ab May 5, 2026 06:02
Copilot AI requested a review from a0x1ab May 5, 2026 06:02
@yonzhan yonzhan assigned calvinhzy and unassigned evelyn-ys May 5, 2026
@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented May 5, 2026

SQL

Copy link
Copy Markdown
Member

@a0x1ab a0x1ab left a comment

Choose a reason for hiding this comment

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

🔄 Iteration 1/3 — Test Failures

Failed Tests

Failure Details

Setup failed:
Cloning into '/tmp/azure-cli-test-squad-32741-1'...
Updating files:  67% (6247/9311)
Updating files:  68% (6332/9311)
Updating files:  69% (6425/9311)
Updating files:  70% (6518/9311)
Updating files:  71% (6611/9311)
Updating files:  72% (6704/9311)
Updating files:  73% (6798/9311)
Updating files:  74% (6891/9311)
Updating files:  75% (6984/9311)
Updating files:  76% (7077/9311)
Updating files:  77% (7170/9311)
Updating files:  78% (7263/9311)
Updating files:  79% (7356/9311)
Updating files:  80% (7449/9311)
Updating files:  81% (7542/9311)
Updating files:  82% (7636/9311)
Updating files:  83% (7729/9311)
Updating files:  84% (7822/9311)
Updating files:  85% (7915/9311)
Updating files:  86% (8008/9311)
Updating files:  87% (8101/9311)
Updating files:  88% (8194/9311)
Updating files:  89% (8287/9311)
Updating files:  90% (8380/9311)
Updating files:  91% (8474/9311)
Updating files:  92% (8567/9311)
Updating files:  93% (8660/9311)
Updating files:  94% (8753/9311)
Updating files:  95% (8846/9311)
Updating files:  96% (8939/9311)
Updating files:  97% (9032/9311)
Updating files:  98% (9125/9311)
Updating files:  98% (9217/9311)
Updating files:  99% (9218/9311)
Updating files: 100% (9311/9311)
Updating files: 100% (9311/9311), done.
From https://github.com/Azure/azure-cli
 * [new branch]      copilot/fix-invalid-retentiondays-error -> origin/copilot/fix-invalid-retentiondays-error
fatal: cannot set up tracking information; starting point 'origin/copilot/fix-invalid-retentiondays-error' is not a branch
failed to run git: exit status 128


Requested Fix

Please address the test failures above. The affected module is sql. Run azdev test sql to validate locally before pushing.


🤖 This comment was generated with AI assistance.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

🔄 Iteration 1/3 — Test Failures

Failed Tests...

The CI failure is a git infrastructure issue in the test runner (fatal: cannot set up tracking information; starting point 'origin/...' is not a branch), not a code failure — the "Failed Tests" section is empty. All unit tests pass locally. No code changes needed.

Copilot finished work on behalf of a0x1ab May 5, 2026 06:08
Copilot AI requested a review from a0x1ab May 5, 2026 06:08
Copy link
Copy Markdown
Member

@a0x1ab a0x1ab left a comment

Choose a reason for hiding this comment

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

🔄 Iteration 2/3 — Test Failures

Failed Tests

Failure Details

Setup failed:
Cloning into '/tmp/azure-cli-test-squad-32741-2'...
Updating files:  79% (7366/9311)
Updating files:  80% (7449/9311)
Updating files:  81% (7542/9311)
Updating files:  82% (7636/9311)
Updating files:  83% (7729/9311)
Updating files:  84% (7822/9311)
Updating files:  85% (7915/9311)
Updating files:  86% (8008/9311)
Updating files:  87% (8101/9311)
Updating files:  88% (8194/9311)
Updating files:  89% (8287/9311)
Updating files:  90% (8380/9311)
Updating files:  91% (8474/9311)
Updating files:  92% (8567/9311)
Updating files:  93% (8660/9311)
Updating files:  94% (8753/9311)
Updating files:  95% (8846/9311)
Updating files:  96% (8939/9311)
Updating files:  97% (9032/9311)
Updating files:  98% (9125/9311)
Updating files:  99% (9218/9311)
Updating files: 100% (9311/9311)
Updating files: 100% (9311/9311), done.
From https://github.com/Azure/azure-cli
 * [new branch]      copilot/fix-invalid-retentiondays-error -> origin/copilot/fix-invalid-retentiondays-error
fatal: cannot set up tracking information; starting point 'origin/copilot/fix-invalid-retentiondays-error' is not a branch
failed to run git: exit status 128


Requested Fix

Please address the test failures above. The affected module is sql. Run azdev test sql to validate locally before pushing.


🤖 This comment was generated with AI assistance.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

🔄 Iteration 2/3 — Test Failures

Failed Tests...

This is the same git infrastructure failure as iteration 1 — the test runner cannot set up git tracking for the branch after cloning. No tests actually ran or failed (the "Failed Tests" section is empty). All 4 unit tests continue to pass locally. There is no code issue to address here.

Copilot finished work on behalf of a0x1ab May 5, 2026 06:13
Copilot AI requested a review from a0x1ab May 5, 2026 06:13
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.

az sql server update - Invalid value given for parameter RetentionDays error - No RetentionDays passed as an argument and no way to do it

5 participants