Skip to content

[PostgreSQL] az postgres flexible-server server-logs list: Fix 33090, command crashes with an AttributeError when listing log files#33096

Open
nachoalonsoportillo wants to merge 6 commits intoAzure:devfrom
nachoalonsoportillo:fix-breaking-change-introduced-with-latest-SDK
Open

[PostgreSQL] az postgres flexible-server server-logs list: Fix 33090, command crashes with an AttributeError when listing log files#33096
nachoalonsoportillo wants to merge 6 commits intoAzure:devfrom
nachoalonsoportillo:fix-breaking-change-introduced-with-latest-SDK

Conversation

@nachoalonsoportillo
Copy link
Copy Markdown
Member

@nachoalonsoportillo nachoalonsoportillo commented Mar 28, 2026

Related command

Description
az postgres flexible-server server-logs list crashes with an AttributeError when listing log files.

File ".../azure/cli/command_modules/postgresql/flexible_server_custom_postgres.py", line 1317, in flexible_server_list_log_files_with_filter
    del f.created_time
        ^^^^^^^^^^^^^^
AttributeError: 'CapturedLog' object has no attribute 'created_time'

Here are the significant differences between LogFile (old) and CapturedLog (new):

Field changes

Aspect LogFile (old) CapturedLog (new)
Class name LogFile CapturedLog
type field name type_properties_type (renamed to avoid collision with ARM's type) type (inside CapturedLogProperties)
type values Undocumented free string Documented: 'ServerLogs' or 'UpgradeLogs'
system_data Absent Present (ARM createdBy/modifiedBy metadata)
Properties nesting Flat on the model Nested in CapturedLogProperties, flattened via __flattened_items

Read-only enforcement
In the old SDK, created_time and last_modified_time were declared readonly: True in _validation — i.e., server-side only. In the new SDK, both are declared with full CRUD visibility (["read", "create", "update", "delete", "query"]), removing the hard read-only constraint at the SDK layer.

SDK generation style
The old SDK was AutoRest-generated (_serialization.Model, _validation, _attribute_map dicts). The new SDK uses the Python Code Generator (_Model, rest_field, @overload constructors). This changes how serialization and validation are expressed, though the wire format is the same.

For now, let's fix it like this. My proposal is to also add a deprecation note to inform that shape of returned object will change in the future to, at least, surface createdTime. We could also consider renaming typePropertiestype to something like logType.

Testing Guide
I noticed that the existing tests weren't running the `server-logs list' command when live test was run. That would have caught the error before we would have merged the PR that introduced the offending SDK. So, I've enable it and refreshed the recordings.

History Notes

[PostgreSQL] az postgres flexible-server server-logs list: Fix 33090, command crashes with an AttributeError when listing log files


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

Copilot AI review requested due to automatic review settings March 28, 2026 19:08
@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Mar 28, 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

Hi @nachoalonsoportillo,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

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

azure-client-tools-bot-prd bot commented Mar 28, 2026

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

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Mar 28, 2026

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

@github-actions
Copy link
Copy Markdown

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>

@nachoalonsoportillo
Copy link
Copy Markdown
Member Author

Fixes #33090.

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 updates the PostgreSQL flexible-server server logs listing implementation to sanitize captured log file objects before returning them, specifically to remove created_time-related fields that are causing SDK compatibility issues.

Changes:

  • Added _sanitize_log_file() helper to convert log file objects into dictionaries and recursively remove created_time variants.
  • Updated flexible_server_list_log_files_with_filter and flexible_server_log_list to return sanitized log file dictionaries instead of mutating SDK objects.

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

@nachoalonsoportillo nachoalonsoportillo changed the title [PostgreSQL] Sanitize log file objects to ensure SDK compatibility by… [PostgreSQL] az postgres flexible-server server-logs list: BUG FIX, command crashes with an AttributeError when listing log files Mar 28, 2026
…og file generation wait logic

- Removed the conditional return for live tests.
- Combined the environment variable check with the sleep function to streamline the waiting period for log file generation.
@nasc17
Copy link
Copy Markdown
Member

nasc17 commented Mar 30, 2026

@calvinhzy and @yonzhan please trigger checks

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Mar 31, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@nachoalonsoportillo nachoalonsoportillo changed the title [PostgreSQL] az postgres flexible-server server-logs list: BUG FIX, command crashes with an AttributeError when listing log files [PostgreSQL] az postgres flexible-server server-logs list: Fix 33090, command crashes with an AttributeError when listing log files Mar 31, 2026
@nasc17
Copy link
Copy Markdown
Member

nasc17 commented Mar 31, 2026

@calvinhzy and @yonzhan please trigger checks, fix we put in for the title, and we needed this for the April release

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Apr 1, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

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 2 out of 3 changed files in this pull request and generated 5 comments.


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


# wait for around 30 min to allow log files to be generated
sleep(30*60)
os.environ.get(ENV_LIVE_TEST, False) and sleep(30*60) # wait for around 30 min to allow log files to be generated
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.

os.environ.get(...) returns a string when the variable is set; values like 'false'/'0' are still truthy and will trigger the sleep unexpectedly. Prefer parsing the env var to a real boolean (or using the existing test framework helpers for live/playback detection) and use an explicit if instead of and for side effects.

Suggested change
os.environ.get(ENV_LIVE_TEST, False) and sleep(30*60) # wait for around 30 min to allow log files to be generated
live_test_flag = os.environ.get(ENV_LIVE_TEST, "")
is_live_test = live_test_flag.lower() in ("1", "true", "yes", "y", "on")
if is_live_test:
sleep(30 * 60) # wait for around 30 min to allow log files to be generated

Copilot uses AI. Check for mistakes.

# wait for around 30 min to allow log files to be generated
sleep(30*60)
os.environ.get(ENV_LIVE_TEST, False) and sleep(30*60) # wait for around 30 min to allow log files to be generated
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.

A fixed 30-minute sleep in live tests can significantly increase pipeline duration and may cause timeouts/flakiness. Consider polling server-logs list until at least one expected log appears (with a bounded timeout and short backoff), or reduce the wait and make the test resilient to empty results.

Copilot uses AI. Check for mistakes.
Comment on lines +37 to +39
# Add systemData if not present (for backward compatibility)
if 'systemData' not in result:
result['systemData'] = None
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.

Adding systemData (even as None) changes the command output shape for consumers that were previously on the older SDK (where this field did not exist). If the intent is to preserve the legacy contract, it’s safer to omit systemData from the returned dict (and potentially strip it when present) rather than always introducing the key.

Suggested change
# Add systemData if not present (for backward compatibility)
if 'systemData' not in result:
result['systemData'] = None
# Remove systemData to preserve the legacy output contract
result.pop('systemData', None)

Copilot uses AI. Check for mistakes.
Comment on lines +30 to +31
if 'createdTime' in properties:
del properties['createdTime'] # Remove created_time as it's not in the original SDK model
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 PR description proposes adding a deprecation note warning that the returned shape will change in the future to surface createdTime, but this change isn’t reflected in the code/help here. Either add the deprecation notice (e.g., command help text/release note) or remove that claim from the description to keep them aligned.

Copilot uses AI. Check for mistakes.
properties = result.pop('properties')
# Extract type from properties and rename to typePropertiesType
if 'createdTime' in properties:
del properties['createdTime'] # Remove created_time as it's not in the original SDK model
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 inline comment uses the snake_case name created_time, but the code is deleting the serialized key createdTime. Updating the comment to match the actual key being removed would prevent confusion during future SDK transitions.

Suggested change
del properties['createdTime'] # Remove created_time as it's not in the original SDK model
del properties['createdTime'] # Remove createdTime as it's not in the original SDK model

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