Skip to content

Write split db-report downloads as a zip#16

Open
jiatolentino wants to merge 1 commit into
datamasque:mainfrom
jiatolentino:db-report-zip-download
Open

Write split db-report downloads as a zip#16
jiatolentino wants to merge 1 commit into
datamasque:mainfrom
jiatolentino:db-report-zip-download

Conversation

@jiatolentino

@jiatolentino jiatolentino commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

dm discover db-report now handles the split-zip format: when the server returns a zip of CSV parts, the CLI writes it as a binary .zip instead of mangling it as text.

Background

Large discovery reports are now split server-side into a zip of numbered CSV parts (datamasque DM-3165). datamasque-python's get_db_discovery_result_report returns bytes for that case.

What changed

  • db-report branches on the client return type:
    • str (CSV) → unchanged (write to -o, or echo to stdout).
    • bytes (zip) → write the binary archive, correcting a non-.zip output path to .zip. Requires -o (a binary zip can't be streamed to stdout); aborts with a clear hint otherwise.

Testing

  • pytest tests/commands/test_discovery.py — added split-zip and no-output abort tests.
  • ruff, ruff format, mypy clean.

Dependency

  • Depends on datamasque-python returning bytes for split reports (companion PR). Bump the minimum datamasque-python pin once that release is cut — otherwise an older client returns corrupt text against a new server.

@jiatolentino jiatolentino self-assigned this Jun 17, 2026
@jiatolentino jiatolentino requested a review from alxboyle June 18, 2026 02:13
@jiatolentino jiatolentino marked this pull request as ready for review June 18, 2026 02:13
@jiatolentino jiatolentino requested review from carlosfunk and removed request for alxboyle June 22, 2026 22:01
code=ErrorCode.INVALID_INPUT,
hint=f"Re-run with -o <path>.zip (e.g. -o discovery_report_{run_id}.zip).",
)
target = output if output.suffix.lower() == ".zip" else output.with_suffix(".zip")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

a file like report.2026.06 would be converted to report.2026.zip

Suggested change
target = output if output.suffix.lower() == ".zip" else output.with_suffix(".zip")
target = output if output.suffix.lower() == ".zip" else output.parent / (output.name + ".zip")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Applied your suggestion (output.parent / (output.name + ".zip")), so multi-dot names are preserved: report.2026.06 → report.2026.06.zip instead of report.2026.zip. Added a regression test using that exact name.

@jiatolentino jiatolentino force-pushed the db-report-zip-download branch from 91b654c to 68a5147 Compare June 22, 2026 23:42
@jiatolentino jiatolentino requested a review from carlosfunk June 22, 2026 23:48
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