Skip to content

Potential fix for code scanning alert no. 2: Variable defined multiple times#69

Merged
zliang-akamai merged 1 commit intomainfrom
alert-autofix-2
Feb 4, 2026
Merged

Potential fix for code scanning alert no. 2: Variable defined multiple times#69
zliang-akamai merged 1 commit intomainfrom
alert-autofix-2

Conversation

@zliang-akamai
Copy link
Copy Markdown
Member

Potential fix for https://github.com/linode/py-metadata/security/code-scanning/2

In general, when a variable or function is defined multiple times without the earlier definition being used, you should either remove the earlier definition or rename one of them so all intended code paths are reachable. For pytest tests, having two functions with the same name in the same module means only the second definition is discoverable and runnable; the first is effectively lost.

Here, the best fix without changing existing functionality is to give the synchronous and asynchronous tests distinct names, so both can run. We keep the bodies exactly the same and only adjust the first function name to something unique, e.g., test_get_ssh_keys_sync. This preserves the synchronous test, preserves the async test and its marker, and resolves the CodeQL complaint that the first assignment to test_get_ssh_keys is unnecessary.

Concretely, in test/integration/test_ssh.py, change line 8 from def test_get_ssh_keys(client: MetadataClient): to def test_get_ssh_keys_sync(client: MetadataClient):. No imports, methods, or other definitions are needed beyond this rename.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…e times

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@zliang-akamai zliang-akamai marked this pull request as ready for review February 3, 2026 03:43
@zliang-akamai zliang-akamai requested a review from a team as a code owner February 3, 2026 03:43
@zliang-akamai zliang-akamai requested review from lgarber-akamai and vshanthe and removed request for a team February 3, 2026 03:43
Copy link
Copy Markdown
Contributor

@vshanthe vshanthe left a comment

Choose a reason for hiding this comment

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

Valid fix 👍

@zliang-akamai zliang-akamai merged commit 87c8be4 into main Feb 4, 2026
13 checks passed
@zliang-akamai zliang-akamai deleted the alert-autofix-2 branch February 4, 2026 06:25
@zliang-akamai zliang-akamai added the testing for updates to the testing suite in the changelog. label Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing for updates to the testing suite in the changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants