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

add the ZAPI request id on RequestError message #52

Merged
merged 3 commits into from
Oct 24, 2023
Merged

Conversation

BurnzZ
Copy link
Contributor

@BurnzZ BurnzZ commented Oct 24, 2023

@codecov-commenter
Copy link

codecov-commenter commented Oct 24, 2023

Codecov Report

Merging #52 (3c6f2db) into main (91b141e) will decrease coverage by 0.36%.
The diff coverage is 0.00%.

❗ Current head 3c6f2db differs from pull request most recent head e288c75. Consider uploading reports for the commit e288c75 to get more accurate results

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #52      +/-   ##
==========================================
- Coverage   43.28%   42.93%   -0.36%     
==========================================
  Files          10       10              
  Lines         365      368       +3     
  Branches       53       54       +1     
==========================================
  Hits          158      158              
- Misses        205      208       +3     
  Partials        2        2              
Files Coverage Δ
zyte_api/aio/client.py 34.66% <ø> (ø)
zyte_api/aio/errors.py 56.25% <0.00%> (-12.99%) ⬇️

@BurnzZ
Copy link
Contributor Author

BurnzZ commented Oct 24, 2023

Tox is failling for 3.7. I suppose removing it would be apt. #53

zyte_api/aio/client.py Outdated Show resolved Hide resolved
@BurnzZ BurnzZ mentioned this pull request Oct 24, 2023
1 task


@pytest.mark.asyncio
@mock.patch("zyte_api.aio.client._post_func")
Copy link
Collaborator

Choose a reason for hiding this comment

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

As for the test, it could be nice to move the mockserver implementation from scrapy-zyte-api to python-zyte-api (see https://github.com/scrapy-plugins/scrapy-zyte-api/blob/137050522c14e146ed6bb28acc31dfde3fbdb6dd/tests/mockserver.py#L55); this would allow writing tests without using mocks.

Please let me know if you want to give it a try, or if you prefer for it to be handled separately; I'm fine with merging without it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this won't be needed with the latest changes since it's simpler now and doesn't need mocks.

@@ -23,4 +26,5 @@ def parsed(self):

def __str__(self):
return f"RequestError: {self.status}, message={self.message}, " \
Copy link
Collaborator

Choose a reason for hiding this comment

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

it seems request_id is going to be included twice here: in self.message, and in self.request_id as well.


@pytest.mark.asyncio
@mock.patch("zyte_api.aio.client._post_func")
async def test_request_raw_error(mock_post):
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems we can check the complete str representation of the error in this test, maybe in addition to the existing checks. Do you see any downsides to it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. 👍

What do you think about not including the request_id in the RequestError.message and then we update https://github.com/scrapy-plugins/scrapy-zyte-api/blob/main/scrapy_zyte_api/handler.py#L223-L224 to ensure request_id is logged via er.request_id?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This sounds fine to me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We'd need to ensure to bump min python-zyte-api version in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome. This makes it much simpler. e288c75

Will have another PR for python-zyte-api after this is merged.

@kmike kmike merged commit 07cc970 into main Oct 24, 2023
7 checks passed
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.

3 participants