Skip to content

Fix draft listing for current Substack API responses - #78

Merged
ma2za merged 1 commit into
ma2za:mainfrom
giacomo-folli:fix-drafts-list-response
Sep 27, 2026
Merged

ma2za merged 1 commit into
ma2za:mainfrom
giacomo-folli:fix-drafts-list-response

Conversation

@giacomo-folli

Copy link
Copy Markdown
Contributor

Api.get_drafts() previously returned the entire response object, while callers expected a list of draft records. This caused drafts list and other draft-management operations to handle the response incorrectly.

This PR extracts the draft records from the posts field while preserving compatibility with responses that already return a list.

Details

The drafts API response format includes pagination metadata alongside the draft records. Returning the complete dictionary from Api.get_drafts() breaks consumers that expect to iterate over draft objects.

For example, the CLI expects to process each draft with calls such as:

draft.get("id")
draft.get("title")

When the response envelope is returned directly, those callers receive the dictionary itself instead of the list under posts.

Implementation

Api.get_drafts() now:

  1. Handles the API response through the existing response helper.
  2. Detects responses containing a list-valued posts field.
  3. Returns that list to preserve the existing method contract.
  4. Falls back to returning the original response for compatibility with older or alternative response formats.

Test Coverage

Added a regression test that verifies:

  • A response containing posts, hasMore, and nextCursor is handled correctly.
  • Api.get_drafts() returns only the draft records.
  • Existing draft-list behavior remains compatible with callers expecting a list.

Documentation

Added an Unreleased changelog entry describing the fix.

The formatting hooks also normalized existing formatting in the widget-preservation implementation and test files. These changes are formatting-only and do not alter their behavior.

@ma2za ma2za left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Reviewed the response normalization and all callers. Returning the posts list preserves the CLI and internal list contract while retaining legacy list responses. Offline tests, the merge result against current main, package builds, and CI across Python 3.10–3.14 pass.

@ma2za
ma2za merged commit 267607c into ma2za:main Sep 27, 2026
7 checks passed
ma2za added a commit that referenced this pull request Sep 27, 2026
Fix draft listing for current Substack API responses
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