Skip to content

[PostgreSQL] az postgres flexible-server: Improved validation logic and style of error messages#33114

Open
nachoalonsoportillo wants to merge 3 commits intoAzure:devfrom
nachoalonsoportillo:review-style-of-error-messages
Open

[PostgreSQL] az postgres flexible-server: Improved validation logic and style of error messages#33114
nachoalonsoportillo wants to merge 3 commits intoAzure:devfrom
nachoalonsoportillo:review-style-of-error-messages

Conversation

@nachoalonsoportillo
Copy link
Copy Markdown
Member

  • Updated comments in test files to improve clarity and consistency.
  • Enhanced error messages in validators for better user guidance and understanding.
  • Standardized phrasing and capitalization in error messages across various validators.
  • Improved validation logic to ensure clearer feedback for incorrect usage.

Related command
az postgres flexible-server

Description
Provided consistency to validations (now all are case-insensitive), and consistent style to error messages produced from validators/

Testing Guide
Ran all tests in live mode to get new recordings and make sure that they all pass.

History Notes

[PostgreSQL] az postgres flexible-server: Improved validation logic and style of error messages


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

- Updated comments in test files to improve clarity and consistency.
- Enhanced error messages in validators for better user guidance and understanding.
- Standardized phrasing and capitalization in error messages across various validators.
- Improved validation logic to ensure clearer feedback for incorrect usage.
Copilot AI review requested due to automatic review settings April 1, 2026 00:01
@azure-client-tools-bot-prd
Copy link
Copy Markdown

Validation for Azure CLI Full Test Starting...

Thanks for your contribution!

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

Validation for Breaking Change Starting...

Thanks for your contribution!

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Apr 1, 2026

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the az postgres flexible-server user experience by standardizing validator behavior (case-insensitive comparisons) and making validator error messages clearer and more consistent, along with updating test comments for clarity.

Changes:

  • Standardize/clarify many validator error messages and make several validations case-insensitive.
  • Refine validation logic around elastic clusters, SSDv2 storage, HA/zonal resiliency, maintenance window, public access, etc.
  • Update PostgreSQL flexible-server scenario tests with clearer step comments and additional negative-test scenarios.

Reviewed changes

Copilot reviewed 19 out of 48 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/azure-cli/azure/cli/command_modules/postgresql/utils/validators.py Updates validator logic and standardizes error message wording/capitalization.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands.py Improves scenario test comments and expands validator negative-test coverage.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_vnet.py Comment-only clarity improvements for vnet scenarios.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_upgrade.py Comment-only clarity improvements for upgrade scenario.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_ssdv2.py Comment-only clarity improvements for SSDv2 scenarios.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_server_logs.py Comment-only clarity improvements for server logs scenarios.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_restore.py Comment-only clarity improvements for restore scenarios.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_replica.py Comment-only clarity improvements for replica/virtual endpoint scenarios.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_private_dns_zone.py Comment updates and scenarios around private DNS zone validation/linking.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_migration.py Comment-only clarity improvements for migration scenarios.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_ltr.py Comment-only clarity improvements for long-term retention scenarios.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_identity_microsoft_entra_admin.py Comment-only clarity improvements for identity/Entra admin scenarios.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_identity_cmk.py Comment-only clarity improvements for CMK scenarios.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_geo_restore.py Comment-only clarity improvements for geo-restore scenario.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_firewall_rule.py Comment-only clarity improvements for firewall/public access scenarios.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_fabric_mirroring.py Comment-only clarity improvements for fabric mirroring scenario.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_elastic_clusters.py Comment-only clarity improvements for elastic cluster scenario.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_backup.py Comment-only clarity improvements for backup scenarios.
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_advanced_threat_protection.py Comment-only clarity improvements for ATP setting scenario.

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 19 out of 48 changed files in this pull request and generated 5 comments.


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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 19 out of 48 changed files in this pull request and generated 4 comments.


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

Comment on lines 747 to +753
def pg_restore_validator(compute_tier, **args):
is_ssdv2_enabled = args.get('storage_type', None) == "PremiumV2_LRS"
is_ssdv2_enabled = args.get('storage_type', None) is not None \
and args.get('storage_type').lower() == 'premiumv2_lrs'

if is_ssdv2_enabled and compute_tier.lower() == 'burstable':
raise ValidationError("Burstable tier is not supported for servers with Premium SSD V2.")
raise ValidationError('Invalid value for --tier. Burstable tier is not supported for servers with '
'--storage-type set to "PremiumV2_LRS".')
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

In pg_restore_validator, the error message says "Invalid value for --tier", but az postgres flexible-server restore doesn't expose a --tier parameter (the tier comes from the source server). This can confuse users who didn't set a tier. Consider rewording to reference the source server tier / the incompatible --storage-type PremiumV2_LRS combination instead of --tier.

Copilot uses AI. Check for mistakes.
Comment on lines 208 to 211
def _cluster_validator(create_cluster, cluster_size, auto_grow, version, tier, instance):
if create_cluster == 'ElasticCluster' or (instance and instance.cluster and instance.cluster.cluster_size > 0):
if create_cluster and create_cluster.lower() == 'elasticcluster' or \
(instance and instance.cluster and instance.cluster.cluster_size > 0):
if instance is None and version != '17':
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

The condition in _cluster_validator mixes and/or without explicit parentheses (if create_cluster and ... or (instance and ...)). Although Python precedence makes this work today, it's easy to misread and accidentally change behavior later. Add parentheses to make the intended grouping explicit.

Copilot uses AI. Check for mistakes.
Comment on lines +195 to 233
# Create server with invalid tier
self.cmd('postgres flexible-server create -g {} -n {} -l {} --tier {}'.format(
resource_group, server_name, location, invalid_tier),
expect_failure=True)

# Create server with invalid version
self.cmd('postgres flexible-server create -g {} -n {} -l {} --version {}'.format(
resource_group, server_name, location, invalid_version),
expect_failure=True)

# Create server with invalid sku name
self.cmd('postgres flexible-server create -g {} -n {} -l {} --tier {} --sku-name {}'.format(
resource_group, server_name, location, valid_tier, invalid_sku_name),
expect_failure=True)

# Create server with invalid backup retention days
self.cmd('postgres flexible-server create -g {} -n {} -l {} --backup-retention {}'.format(
resource_group, server_name, location, invalid_backup_retention),
expect_failure=True)

# Create server with zone redundant high availability in a location that does not support it, because it's a single zone location
self.cmd('postgres flexible-server create -g {} -n {} -l {} --high-availability {} '.format(
resource_group, server_name, location, ha_value),
expect_failure=True)

# high availability validator
# Create server with zone redundant high availability with a tier that does not support it
self.cmd('postgres flexible-server create -g {} -n {} -l {} --tier Burstable --sku-name Standard_B1ms --high-availability {}'.format(
resource_group, server_name, location, ha_value),
expect_failure=True)

# Create server with zone redundant high availability in a location that does not support it, because it's a single zone location
self.cmd('postgres flexible-server create -g {} -n {} -l {} --tier GeneralPurpose --sku-name Standard_D4ds_v4 --high-availability {}'.format(
resource_group, server_name, location, ha_value), # single availability zone location
resource_group, server_name, location, ha_value),
expect_failure=True)

# Create server with zone redundant high availability and forcing same zone for primary and standby
self.cmd('postgres flexible-server create -g {} -n {} -l {} --tier GeneralPurpose --sku-name Standard_D2ads_v5 --high-availability {} --zone 1 --standby-zone 1'.format(
resource_group, server_name, location, ha_value), # single availability zone location
resource_group, server_name, location, ha_value),
expect_failure=True)
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

In _test_mgmt_create_validator, multiple postgres flexible-server create calls reuse the same server_name and only assert expect_failure=True. If any command unexpectedly succeeds (e.g., due to capability changes), subsequent creates may fail due to name collision and still satisfy expect_failure, masking the real regression and potentially leaking a live server. Consider generating a unique name per negative case and/or asserting on the specific validation error text.

Copilot uses AI. Check for mistakes.
Comment on lines 100 to +104
self.cmd('network private-dns link vnet create -g {} -n MyLinkName -z {} -v {} -e False'.format(
vnet_resource_group, vnet_group_dns_zone, vnet_group_vnet['id']
))

# Create server with the private DNS zone that is linked to the vnet in a different resource group
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

There appears to be trailing whitespace on the blank line after the network private-dns link vnet create call, which can cause noisy diffs and may fail whitespace-sensitive linters. Remove the extra spaces so the line is truly blank.

Copilot uses AI. Check for mistakes.
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.

5 participants