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

Remove the experimental name space from cookie parameters #144

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

Gallaecio
Copy link
Contributor

@Gallaecio Gallaecio commented Nov 2, 2023

To do:

Fixes #243.

Copy link

codecov bot commented Nov 3, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.74%. Comparing base (83d69bd) to head (95af836).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #144      +/-   ##
==========================================
+ Coverage   97.68%   97.74%   +0.05%     
==========================================
  Files          14       14              
  Lines        1726     1770      +44     
  Branches      315      332      +17     
==========================================
+ Hits         1686     1730      +44     
  Misses         18       18              
  Partials       22       22              
Files with missing lines Coverage Δ
scrapy_zyte_api/_cookies.py 83.78% <100.00%> (+0.45%) ⬆️
scrapy_zyte_api/_params.py 100.00% <100.00%> (ø)
scrapy_zyte_api/_request_fingerprinter.py 98.88% <100.00%> (+0.06%) ⬆️
scrapy_zyte_api/responses.py 96.15% <100.00%> (+0.03%) ⬆️

Comment on lines +9 to +11
* If the ``COOKIES_ENABLED`` setting is ``True`` (default), automatic request
parameter mapping now sets ``responseCookies`` to ``True`` and maps request
cookies to ``requestCookies``.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This means that, by default, all Zyte API requests with automap will start including "responseCookies": True among their parameters. Similar to how we do with httpResponseHeaders, but in this case the behavior also affects browser rendering and automatic extraction scenarios. The test expectation updates are a great way to get an idea of the impact.

This is a big one, the reason I went for 0.13.0 instead of 0.12.3, and I wonder whether or not this is the right call. I wonder if we should implement an opt-in setting for responseCookies, or make it so that it is only added to requests if requestCookies is also added (either manually by the user our automatically mapped).

):
for field in list(self._unreported_deprecated_experimental_fields):
if field in params["experimental"]:
self._unreported_deprecated_experimental_fields.remove(field)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went with this to warn only once. I wonder if it is overkill, or even if it is better to log a warning on every request to encourage a fix and minimize the chance of users missing the warning message (i.e. if you are already ignoring a couple of warnings, you might not notice the extra one).

Comment on lines 739 to 745
logger.warning(
f"Zyte API parameters for request {request} include "
f"experimental.{field}, which is deprecated. Please, "
f"replace it with {field}, both in request parameters "
f"and in any response parsing logic that might rely "
f"on the old parameter."
)
Copy link
Contributor Author

@Gallaecio Gallaecio Nov 3, 2023

Choose a reason for hiding this comment

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

I went with logging warning messages (here and in all other places in this PR) instead of using warnings.warn with DeprecationWarning mostly because it made it easier to use tests (which already had warning log support). I also wonder if logging a warning might be better for Scrapy Cloud support, or other cloud systems. But no strong opinion.

@Gallaecio Gallaecio requested review from kmike and wRAR November 3, 2023 15:00
@Gallaecio Gallaecio marked this pull request as ready for review November 3, 2023 15:00
@Gallaecio
Copy link
Contributor Author

Question: should we disable some aspects of automatic cookie mapping when using a session or a pool of sessions? I wonder if, in that case, we should not add responseCookies automatically. I also wonder if we should do the same with requestCookies, and if so, if it should be conditional on something (e.g. whether the cookies come from the cookiejar, from being explicitly set on Request.cookies, or if we do map the cookiejar, if it should make a difference whether it is the default cookiejar or one with an explicit cookiejar ID.

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.

Zyte API cookies are no longer experimental
1 participant