Skip to content

fix: log S3 response body on cache upload failure - #117

Merged
tkislan merged 4 commits into
mainfrom
fix/sql-cache-upload-error-body
Aug 11, 2026
Merged

fix: log S3 response body on cache upload failure#117
tkislan merged 4 commits into
mainfrom
fix/sql-cache-upload-error-body

Conversation

@tkislan

@tkislan tkislan commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

raise_for_status() only surfaces 403 Forbidden — the S3 XML error body is the only place that distinguishes AccessDenied / Request has expired / SignatureDoesNotMatch / expired presigned URL. This reads exc.response.text so the reason reaches the log.

Before

Failed to upload SQL cache: 403 Client Error: Forbidden for url: https://bucket.s3.../cache/abc?X-Amz-Credential=AKIA...&X-Amz-Signature=deadbeef

Status code only, no reason. Presigned URL with signing params leaked into the log.

After

Failed to upload SQL cache: 403 <?xml version="1.0"?><Error><Code>AccessDenied</Code><Message>Request has expired</Message><Expires>...</Expires></Error>

S3 error body with the actual reason. Presigned URL no longer logged for HTTP errors.

Non-HTTP exceptions (ConnectionError, Timeout) still fall through to str(exc) — unchanged from main.

🤖 Generated with Claude Code

https://claude.ai/code/session_018cayDdcs1iuui8Pgh5npKm

Summary by CodeRabbit

  • Bug Fixes

    • Improved SQL cache upload error messages with HTTP status codes and up to 500 characters of response details.
    • Preserved clear exception messages for connection-related and other non-HTTP failures.
    • Prevented upload URLs from appearing in logged error details.
  • Tests

    • Added coverage for HTTP and connection error logging.
    • Verified that response details are included safely without exposing sensitive upload URLs.

raise_for_status() only gives "403 Forbidden" — the S3 error body
(AccessDenied, Request has expired, SignatureDoesNotMatch, etc.) is
the only place that says why. Read it off exc.response.text.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018cayDdcs1iuui8Pgh5npKm
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown

📦 Python package built successfully!

  • Version: 2.4.0.dev6+8abb90d
  • Wheel: deepnote_toolkit-2.4.0.dev6+8abb90d-py3-none-any.whl
  • Install:
    pip install "deepnote-toolkit @ https://deepnote-staging-runtime-artifactory.s3.amazonaws.com/deepnote-toolkit-packages/2.4.0.dev6%2B8abb90d/deepnote_toolkit-2.4.0.dev6%2B8abb90d-py3-none-any.whl"

@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.46%. Comparing base (b2e36e8) to head (d9a1796).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #117      +/-   ##
==========================================
+ Coverage   74.42%   74.46%   +0.04%     
==========================================
  Files          95       95              
  Lines        5704     5707       +3     
  Branches      850      851       +1     
==========================================
+ Hits         4245     4250       +5     
+ Misses       1182     1180       -2     
  Partials      277      277              
Flag Coverage Δ
combined 74.46% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@deepnote-bot

deepnote-bot commented Aug 10, 2026

Copy link
Copy Markdown

🚀 Review App Deployment Started

📝 Description 🌐 Link / Info
🌍 Review application ra-117
🔑 Sign-in URL Click to sign-in
📊 Application logs View logs
🔄 Actions Click to redeploy
🚀 ArgoCD deployment View deployment
Last deployed 2026-08-11 10:23:14 (UTC)
📜 Deployed commit c81f095427a0ac8f5e3ae16de65aa164d236c56c
🛠️ Toolkit version 8abb90d

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018cayDdcs1iuui8Pgh5npKm
@tkislan

tkislan commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

SQL cache upload failures now format requests.HTTPError details with the response status and up to 500 characters of response text. Other exceptions retain their string representation. Unit tests cover HTTP and connection errors and verify that upload URLs are not logged.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Updates Docs ⚠️ Warning The PR changes only SQL caching code and unit tests; no documentation or roadmap files were updated for the new HTTP error logging behavior. Update the SQL cache documentation in deepnote/deepnote and the roadmap in deepnote/deepnote-internal. Those repositories are not available in this checkout.
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: logging the S3 response body when cache upload fails.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/unit/test_sql_caching.py (2)

401-401: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add the required docstrings and type hints.

The two new test methods have no docstrings, parameter annotations, or -> None return annotations. Add short docstrings and explicit annotations for mock_put, mock_logger, and the return value.

As per coding guidelines: “Use docstrings for all functions/classes” and “Use explicit type hints for function parameters and return values.”

Also applies to: 421-421

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/test_sql_caching.py` at line 401, Update the new test methods
test_http_error_logs_response_body and the method at the additional referenced
location to include short docstrings, explicit type annotations for mock_put and
mock_logger, and a -> None return annotation, following the annotations already
used by neighboring tests.

Source: Coding guidelines


401-417: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Test the 500-character response-body limit.

The HTTP test uses a short body. Add a response body longer than 500 characters and assert that only the first 500 characters are logged.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/test_sql_caching.py` around lines 401 - 417, Update
test_http_error_logs_response_body to use an HTTP error response body exceeding
500 characters, then assert the logged body contains exactly its first 500
characters and excludes content beyond that limit while preserving the existing
status-code and URL-redaction assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/unit/test_sql_caching.py`:
- Around line 402-410: Update the mocked HTTP response in the relevant SQL cache
upload test to set response.url to upload_url, reuse upload_url for
upload_sql_cache, and inspect repr(mock_logger.error.call_args) to assert
upload_url is absent, ensuring the complete logger call is redacted.

---

Nitpick comments:
In `@tests/unit/test_sql_caching.py`:
- Line 401: Update the new test methods test_http_error_logs_response_body and
the method at the additional referenced location to include short docstrings,
explicit type annotations for mock_put and mock_logger, and a -> None return
annotation, following the annotations already used by neighboring tests.
- Around line 401-417: Update test_http_error_logs_response_body to use an HTTP
error response body exceeding 500 characters, then assert the logged body
contains exactly its first 500 characters and excludes content beyond that limit
while preserving the existing status-code and URL-redaction assertions.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aa53193b-e4f1-4bb4-aac8-ef84ff026c06

📥 Commits

Reviewing files that changed from the base of the PR and between 6198101 and 3573f46.

📒 Files selected for processing (2)
  • deepnote_toolkit/sql/sql_caching.py
  • tests/unit/test_sql_caching.py

Comment thread tests/unit/test_sql_caching.py
The test asserted the presigned upload URL stays out of the log, but never
set response.url on the mock response. raise_for_status() interpolates
response.url into str(exc), so with it unset the exception string read
"for url: None" and the assertion passed against the pre-fix code too.

Setting response.url makes the assertion bite: verified it now fails
against the old str(exc) logging and passes with the status+body format.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018cayDdcs1iuui8Pgh5npKm
@tkislan
tkislan marked this pull request as ready for review August 11, 2026 10:13
@tkislan
tkislan requested a review from a team as a code owner August 11, 2026 10:13
@tkislan
tkislan requested a review from mfranczel August 11, 2026 10:13
@tkislan
tkislan merged commit b288a01 into main Aug 11, 2026
33 checks passed
@tkislan
tkislan deleted the fix/sql-cache-upload-error-body branch August 11, 2026 11:44
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.

3 participants