Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AttributeError by accessing meta field when return_type is dict #1861

Merged
merged 5 commits into from Oct 25, 2022
Merged

Fix AttributeError by accessing meta field when return_type is dict #1861

merged 5 commits into from Oct 25, 2022

Conversation

lqhuang
Copy link
Contributor

@lqhuang lqhuang commented Apr 13, 2022

I meet totally the same error to #1843

Traceback (most recent call last):
  File "${MY_PY_ENV}/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "${MY_PY_ENV}/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "${MY_WORKSPACE}/twitter_fetcher/fetch_tweet_timeline.py", line 174, in <module>
    main()
  File "${MY_WORKSPACE}/twitter_fetcher/fetch_tweet_timeline.py", line 84, in main
    for i, resp in enumerate(
  File "${MY_PY_ENV}/lib/python3.10/site-packages/tweepy/pagination.py", line 100, in __next__
    self.previous_token = response.meta.get("previous_token")
AttributeError: 'dict' object has no attribute 'meta'

My solution is to add an isinstance condition, it's very simple but useful. Any improvement or suggest for this PR is welcome.

Regards.

@lqhuang
Copy link
Contributor Author

lqhuang commented Jul 9, 2022

@Harmon758 Hi, Harmon. Could you please take a look to this PR. Our packages have some functions rely on dict as return_type with tweepy as upstream. If you have other ideas to implement or another consideration about program design, I'm really glad to adapt and help. Thanks to your efforts!

My regards.

@lqhuang

This comment was marked as resolved.

@lqhuang lqhuang changed the title Fix AttributeError by accessing meta field when return_type is dict Fix AttributeError by accessing meta field when return_type is dict Aug 9, 2022
@Harmon758 Harmon758 added the Bug This is regarding a bug with the library label Oct 22, 2022
Copy link
Member

@Harmon758 Harmon758 left a comment

Choose a reason for hiding this comment

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

With AsyncPaginator implemented now, a similar fix needs to be applied to it.
I can add it later if it's not part of this PR.

tweepy/pagination.py Outdated Show resolved Hide resolved
tweepy/pagination.py Show resolved Hide resolved
tweepy/pagination.py Outdated Show resolved Hide resolved
@Harmon758 Harmon758 added the Need Follow-Up This needs to be followed up on to be actionable label Oct 22, 2022
@Harmon758 Harmon758 mentioned this pull request Oct 22, 2022
@lqhuang
Copy link
Contributor Author

lqhuang commented Oct 23, 2022

Here is a marker, previous update messages just show rebased records from the latest master branch.

@Harmon758
Copy link
Member

You've rebased and duplicated 66 commits from the master branch onto your branch.
Either make a merge commit or directly rebase your commits onto an updated version of the branch.

@lqhuang
Copy link
Contributor Author

lqhuang commented Oct 23, 2022

@Harmon758 You can review it now, I have added similar patch to AsyncPaginator and a note part for both pagination classes. But I'm not very sure whether the document content would satisfy you, please check it. Some style refactors are affected by black.

You've rebased and duplicated 66 commits from the master branch onto your branch. Either make a merge commit or directly rebase your commits onto an updated version of the branch.

Yeah, I choose the later one that I actually only do rebase my commits onto the latest master. But it seems my commits are too elder to on top of history. I could rewrite these commits with forced push if you cannot rebase into master safely.

Regards.

@lqhuang
Copy link
Contributor Author

lqhuang commented Oct 23, 2022

Squash rebase is an excellent approach to merge

@Harmon758
Copy link
Member

Harmon758 commented Oct 23, 2022

Again, you've rebased commits from the master branch to your branch, not the other way around.
I'm not going to review over 60 of my own commits changing 80+ files.

@lqhuang
Copy link
Contributor Author

lqhuang commented Oct 24, 2022

@Harmon758 I have fixed that. Sorry for the inconvenience.

Copy link
Member

@Harmon758 Harmon758 left a comment

Choose a reason for hiding this comment

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

AsyncPaginator is meant to be used with AsyncClient, not Client.
AsyncClient uses aiohttp instead of requests and does not ever return requests.Response.

tweepy/pagination.py Outdated Show resolved Hide resolved
tweepy/pagination.py Outdated Show resolved Hide resolved
@lqhuang
Copy link
Contributor Author

lqhuang commented Oct 24, 2022

Sorry, my faults, I forgot to check async http client.

tweepy/asynchronous/pagination.py Outdated Show resolved Hide resolved
tweepy/pagination.py Outdated Show resolved Hide resolved
@lqhuang
Copy link
Contributor Author

lqhuang commented Oct 25, 2022

Really thank you for your patience. 👍

@Harmon758 Harmon758 removed the Need Follow-Up This needs to be followed up on to be actionable label Oct 25, 2022
@Harmon758 Harmon758 merged commit ac882b3 into tweepy:master Oct 25, 2022
@lqhuang lqhuang deleted the fix-meta-attr-for-paginator branch October 26, 2022 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is regarding a bug with the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pagination is not working with return_type = dict or return_type = requests.Response
2 participants