Skip to content

Automatically compute content_hash for uploads#538

Merged
AndreyVMarkelov merged 1 commit into
mainfrom
auto-content-hash
Jul 13, 2026
Merged

Automatically compute content_hash for uploads#538
AndreyVMarkelov merged 1 commit into
mainfrom
auto-content-hash

Conversation

@AndreyVMarkelov

Copy link
Copy Markdown
Contributor

Summary

Computes the Dropbox content hash of upload payloads and sends it with the request so the server verifies upload integrity, matching the behavior of dropbox-sdk-go #140.

  • dropbox/content_hash.py (new) — DropboxContentHasher / StreamHasher from dropbox-api-content-hasher, adapted for Python 3 (no six), plus a content_hash() helper.
  • auto_content_hash constructor flag (default True) to opt out. Preserved across clone(), as_user()/as_admin(), and with_path_root().
  • Transport fills the content_hash field on upload routes when the caller hasn't supplied one and the payload is bytes. Applies generically to all upload-style routes with a content_hash field (files_upload, files_alpha_upload, upload_session_start/append/append_v2/finish).

No public API change: content_hash was already an optional field on the upload methods; this just fills it in. The logic lives in the hand-written transport so it survives client regeneration, and the caller's argument object is never mutated (a copy is made).

Tests

  • test/unit/test_content_hash.py — hasher algorithm, chunked updates, copy() independence, reuse guard, non-bytes rejection, StreamHasher passthrough.
  • test/unit/test_dropbox_unit.py — auto on/off, caller-provided hash respected, flag propagation across clone/team/path-root.
  • test/integration/test_dropbox.py::test_upload_auto_content_hash — asserts the server-returned content_hash matches the locally computed one (end-to-end).

Unit suite: 56 passed; flake8 clean.

Note

The end-to-end behavior (server accepting and verifying the hash) is only exercised by the integration test, which requires live credentials and runs in CI's Integration job.

@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.19%. Comparing base (620b8be) to head (acb5cce).

Files with missing lines Patch % Lines
dropbox/content_hash.py 89.15% 8 Missing and 1 partial ⚠️
dropbox/dropbox_client.py 87.50% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #538      +/-   ##
==========================================
+ Coverage   65.14%   65.19%   +0.04%     
==========================================
  Files          31       32       +1     
  Lines       54902    55001      +99     
  Branches     3901     3911      +10     
==========================================
+ Hits        35767    35858      +91     
- Misses      18981    18988       +7     
- Partials      154      155       +1     
Flag Coverage Δ
integration 65.01% <54.54%> (-0.02%) ⬇️
unit 64.75% <86.86%> (+0.14%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Compute and send Dropbox content hashes for byte upload payloads by
default. Preserve caller-provided hashes and support opting out.

Add unit and live integration coverage for hashing and request
verification. Run the complete unit suite in CI and coverage jobs.
@AndreyVMarkelov AndreyVMarkelov merged commit e0008c8 into main Jul 13, 2026
31 checks passed
@AndreyVMarkelov AndreyVMarkelov deleted the auto-content-hash branch July 13, 2026 17:34
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.

2 participants