Skip to content

Fix DockerRegistryCredentials and DockerHost to fallback to standard logger#124

Open
tomerqodo wants to merge 3 commits into
qodo_combined-20260114-qodo-grep-copilot_base_fix_dockerregistrycredentials_and_dockerhost_to_fallback_to_standard_logger_pr391from
qodo_combined-20260114-qodo-grep-copilot_head_fix_dockerregistrycredentials_and_dockerhost_to_fallback_to_standard_logger_pr391
Open

Fix DockerRegistryCredentials and DockerHost to fallback to standard logger#124
tomerqodo wants to merge 3 commits into
qodo_combined-20260114-qodo-grep-copilot_base_fix_dockerregistrycredentials_and_dockerhost_to_fallback_to_standard_logger_pr391from
qodo_combined-20260114-qodo-grep-copilot_head_fix_dockerregistrycredentials_and_dockerhost_to_fallback_to_standard_logger_pr391

Conversation

@tomerqodo
Copy link
Copy Markdown

Benchmark PR from qodo-benchmark#391

devin-ai-integration Bot and others added 3 commits January 5, 2026 17:48
…logger

- Update DockerRegistryCredentials.login() to catch MissingContextError and
  fallback to a standard prefect logger when not in a flow run context
- Update DockerHost.get_client() with the same fallback pattern
- Update DockerRegistryCredentials code example to show loading block by name
  to match the default behavior of other blocks

Co-Authored-By: alex.s@prefect.io <ajstreed1@gmail.com>
…yCredentials

- Add test_get_client_works_outside_flow_run_context for DockerHost
- Add test_docker_registry_credentials_login_works_outside_flow_run_context for DockerRegistryCredentials
- Both tests verify the logger fallback works without raising MissingContextError

Co-Authored-By: alex.s@prefect.io <ajstreed1@gmail.com>
@qodo-code-review
Copy link
Copy Markdown

Code Review by Qodo (Alpha)

🐞 Bugs (1) 📘 Rule Violations (1) 📎 Requirement Gaps (0) 💡 Suggestions (0)

Grey Divider


Action Required

1. `logger` undefined in `get_client` 📘 Rule Violation
Description
DockerHost.get_client() catches MissingContextError but does not initialize a fallback logger,
  leaving logger potentially undefined.
• When the exception path is taken, subsequent logger.debug(...) calls will raise
  UnboundLocalError, preventing client creation and breaking usage outside a flow/task run context.
• This is an unhandled edge case introduced by the change, reducing graceful degradation and
  debuggability.

reliability

Code

src/integrations/prefect-docker/prefect_docker/host.py[R94-97]

+        try:
+            logger = get_run_logger()
+        except MissingContextError:
+            pass
Evidence
PR Compliance ID 3 requires edge cases to be explicitly handled with meaningful context and graceful
degradation. In DockerHost.get_client, the new except MissingContextError: pass leaves logger
unset, but logger.debug(...) is still executed later in the method, creating a failure path
instead of graceful fallback.

Rule 3: Generic: Robust Error Handling and Edge Case Management
src/integrations/prefect-docker/prefect_docker/host.py[94-120]

Agent Prompt
## Issue description
`DockerHost.get_client()` can leave `logger` undefined when `get_run_logger()` raises `MissingContextError`, but the method still calls `logger.debug(...)` later. This can raise `UnboundLocalError` and break creating a Docker client outside a run context.

## Issue Context
The change introduced an exception handler that does `pass` instead of falling back to a standard logger (similar to `DockerRegistryCredentials.login`). The method must gracefully degrade when there is no run context.

## Fix Focus Areas
- src/integrations/prefect-docker/prefect_docker/host.py[94-120]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Test misses reauth arg 🐞 Bug
Description
DockerRegistryCredentials.login always passes reauth=self.reauth to client.login.
• The new test asserts mock_docker_client.login.assert_called_once_with(...) without including
  reauth, so it will fail due to argument mismatch.

correctness

Code

src/integrations/prefect-docker/tests/test_credentials.py[R21-32]

+    credentials = DockerRegistryCredentials(
+        username="test_user",
+        password="test_password",
+        registry_url="registry.hub.docker.com",
+    )
+    # This should not raise MissingContextError
+    await credentials.login(client=mock_docker_client)
+    mock_docker_client.login.assert_called_once_with(
+        username="test_user",
+        password="test_password",
+        registry="registry.hub.docker.com",
+    )
Evidence
The production code invokes client.login with the reauth keyword argument.
assert_called_once_with requires an exact match of kwargs, but the test omits reauth, so the
assertion will not match the actual call.

src/integrations/prefect-docker/prefect_docker/credentials.py[57-70]
src/integrations/prefect-docker/tests/test_credentials.py[17-32]

Agent Prompt
### Issue description
The new unit test asserts `client.login` was called without the `reauth` kwarg, but the implementation always passes `reauth=self.reauth`. This makes the new test fail.

### Issue Context
`DockerRegistryCredentials.reauth` defaults to `True` and is always forwarded to `client.login`.

### Fix Focus Areas
- src/integrations/prefect-docker/tests/test_credentials.py[21-32]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment on lines +94 to +97
try:
logger = get_run_logger()
except MissingContextError:
pass
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action Required

1. logger undefined in get_client 📘 Rule Violation

DockerHost.get_client() catches MissingContextError but does not initialize a fallback logger,
  leaving logger potentially undefined.
• When the exception path is taken, subsequent logger.debug(...) calls will raise
  UnboundLocalError, preventing client creation and breaking usage outside a flow/task run context.
• This is an unhandled edge case introduced by the change, reducing graceful degradation and
  debuggability.
Agent Prompt
## Issue description
`DockerHost.get_client()` can leave `logger` undefined when `get_run_logger()` raises `MissingContextError`, but the method still calls `logger.debug(...)` later. This can raise `UnboundLocalError` and break creating a Docker client outside a run context.

## Issue Context
The change introduced an exception handler that does `pass` instead of falling back to a standard logger (similar to `DockerRegistryCredentials.login`). The method must gracefully degrade when there is no run context.

## Fix Focus Areas
- src/integrations/prefect-docker/prefect_docker/host.py[94-120]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +21 to +32
credentials = DockerRegistryCredentials(
username="test_user",
password="test_password",
registry_url="registry.hub.docker.com",
)
# This should not raise MissingContextError
await credentials.login(client=mock_docker_client)
mock_docker_client.login.assert_called_once_with(
username="test_user",
password="test_password",
registry="registry.hub.docker.com",
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action Required

2. Test misses reauth arg 🐞 Bug

DockerRegistryCredentials.login always passes reauth=self.reauth to client.login.
• The new test asserts mock_docker_client.login.assert_called_once_with(...) without including
  reauth, so it will fail due to argument mismatch.
Agent Prompt
### Issue description
The new unit test asserts `client.login` was called without the `reauth` kwarg, but the implementation always passes `reauth=self.reauth`. This makes the new test fail.

### Issue Context
`DockerRegistryCredentials.reauth` defaults to `True` and is always forwarded to `client.login`.

### Fix Focus Areas
- src/integrations/prefect-docker/tests/test_credentials.py[21-32]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

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.

1 participant