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 19 commits into
base: main
Choose a base branch
from

Conversation

Gallaecio
Copy link
Contributor

@Gallaecio Gallaecio commented Nov 2, 2023

Copy link

codecov bot commented Nov 3, 2023

Codecov Report

Merging #144 (c5f7002) into main (993d2a5) will decrease coverage by 0.36%.
The diff coverage is 95.69%.

❗ Current head c5f7002 differs from pull request most recent head 888ac92. Consider uploading reports for the commit 888ac92 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #144      +/-   ##
==========================================
- Coverage   98.18%   97.83%   -0.36%     
==========================================
  Files          11       11              
  Lines         828      877      +49     
==========================================
+ Hits          813      858      +45     
- Misses         15       19       +4     
Files Coverage Δ
scrapy_zyte_api/_cookies.py 91.89% <100.00%> (+0.22%) ⬆️
scrapy_zyte_api/_request_fingerprinter.py 97.82% <100.00%> (+0.26%) ⬆️
scrapy_zyte_api/responses.py 99.00% <100.00%> (+<0.01%) ⬆️
scrapy_zyte_api/_params.py 98.68% <95.18%> (-1.32%) ⬇️

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).

scrapy_zyte_api/_params.py Outdated Show resolved Hide resolved
scrapy_zyte_api/_params.py Outdated Show resolved Hide resolved
):
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
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