Skip to content

Fix fetchById issue of target location#405

Open
skillradius360 wants to merge 1 commit intod60:mainfrom
skillradius360:patch-1
Open

Fix fetchById issue of target location#405
skillradius360 wants to merge 1 commit intod60:mainfrom
skillradius360:patch-1

Conversation

@skillradius360
Copy link
Copy Markdown

@skillradius360 skillradius360 commented Feb 25, 2026

This is the problem regarding the fetching of target with a X id and then it returns ItemContent... this is fixed and working as intended

Summary by Sourcery

Bug Fixes:

  • Fix incorrect access to reply cursor value that caused fetching by target ID to return wrong content.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed pagination for loading additional replies to ensure proper content retrieval.

This is the problem regarding the fetching of target with a X id and then it returns ItemContent... this is fixed and working as intended
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 25, 2026

📝 Walkthrough

Walkthrough

The _get_more_replies method in the client module has been updated to retrieve the next pagination cursor from a simplified data path structure, removing an intermediate itemContent layer when accessing the cursor value from the last entry.

Changes

Cohort / File(s) Summary
Pagination Cursor Access
twikit/client/client.py
Modified cursor retrieval in _get_more_replies to access entries[-1]['content']['value'] instead of entries[-1]['content']['itemContent']['value'], reflecting a change in response data structure.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A cursor hopped through nested trees,
Through itemContent with such ease,
But now it found a shorter way,
One layer less to skip today—
Pagination swift, the path more clean! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title mentions 'fetchById issue of target location' but the actual change is in _get_more_replies pagination cursor extraction, which is unrelated to fetchById functionality. Clarify whether the title describes the actual change (pagination cursor fix) or if the changeset description is incomplete. Update the title to accurately reflect the _get_more_replies cursor extraction modification.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@twikit/client/client.py`:
- Line 1526: The pagination cursor extraction currently assumes
entries[-1]['content']['value'] and later
entries[-1]['content']['itemContent']['value'] which can KeyError if payload
shape varies; update the extraction used for next_cursor (symbol: next_cursor
and the entries list) to be schema‑tolerant: attempt content['value'], then
content.get('itemContent', {}).get('value') (or equivalent safe lookups),
falling back to None if neither exists, and apply the same tolerant fallback
wherever content.itemContent.value is read (the later read around line with
content.itemContent.value) so both paths handle either shape without raising
KeyError.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b18105 and 383aa41.

📒 Files selected for processing (1)
  • twikit/client/client.py

Comment thread twikit/client/client.py

if entries[-1]['entryId'].startswith('cursor'):
next_cursor = entries[-1]['content']['itemContent']['value']
next_cursor = entries[-1]['content']['value']
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.

⚠️ Potential issue | 🟠 Major

Use schema-tolerant cursor extraction here to avoid pagination breakage.

Line 1526 hardcodes content.value, but the same tweet-detail flow still reads content.itemContent.value at Line 1635. If payload shape differs between pages, one path can fail with KeyError and break reply pagination.

🔧 Proposed hardening
-        if entries[-1]['entryId'].startswith('cursor'):
-            next_cursor = entries[-1]['content']['value']
+        if entries[-1]['entryId'].startswith('cursor'):
+            cursor_content = entries[-1].get('content', {})
+            next_cursor = (
+                cursor_content.get('value')
+                or cursor_content.get('itemContent', {}).get('value')
+            )
+            if next_cursor is None:
+                _fetch_next_result = None
+                return Result(results, _fetch_next_result, None)
             _fetch_next_result = partial(self._get_more_replies, tweet_id, next_cursor)

Also apply the same fallback pattern at Line 1635 for consistency.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@twikit/client/client.py` at line 1526, The pagination cursor extraction
currently assumes entries[-1]['content']['value'] and later
entries[-1]['content']['itemContent']['value'] which can KeyError if payload
shape varies; update the extraction used for next_cursor (symbol: next_cursor
and the entries list) to be schema‑tolerant: attempt content['value'], then
content.get('itemContent', {}).get('value') (or equivalent safe lookups),
falling back to None if neither exists, and apply the same tolerant fallback
wherever content.itemContent.value is read (the later read around line with
content.itemContent.value) so both paths handle either shape without raising
KeyError.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Feb 25, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts how the next pagination cursor is read when loading more replies, fixing incorrect parsing of the API response that caused wrong content to be fetched.

Sequence diagram for loading additional replies with corrected cursor parsing

sequenceDiagram
    actor User
    participant Client
    participant TwitterAPI

    User->>Client: load_more_replies(tweet_id)
    Client->>TwitterAPI: GET replies(tweet_id, cursor)
    TwitterAPI-->>Client: response(entries)

    Client->>Client: inspect last_entry = entries[-1]
    alt last_entry.entryId starts with cursor
        Client->>Client: next_cursor = last_entry.content.value
        Client->>TwitterAPI: GET replies(tweet_id, next_cursor)
        TwitterAPI-->>Client: additional replies
    else no cursor entry
        Client->>Client: next_cursor = None
    end

    Client-->>User: replies list
Loading

File-Level Changes

Change Details Files
Fix pagination cursor extraction when fetching additional replies so that the correct cursor value is used.
  • Change cursor retrieval from the nested 'itemContent.value' field to the direct 'content.value' field for the last cursor entry.
  • Maintain existing logic that checks whether the last entry is a cursor and recursively fetches more replies using the updated cursor value.
twikit/client/client.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The change assumes entries[-1]['content']['value'] always exists; consider using a safer access pattern (e.g., get with a clear error or fallback) to avoid KeyError if the API response shape changes again.
  • If the API can sometimes return itemContent and sometimes not, you might want to handle both shapes (checking for itemContent first, then value) for backward compatibility rather than hard-switching to the new structure.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The change assumes `entries[-1]['content']['value']` always exists; consider using a safer access pattern (e.g., `get` with a clear error or fallback) to avoid `KeyError` if the API response shape changes again.
- If the API can sometimes return `itemContent` and sometimes not, you might want to handle both shapes (checking for `itemContent` first, then `value`) for backward compatibility rather than hard-switching to the new structure.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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