Document that follow_all requests share meta and cb_kwargs values (#7962)

This commit is contained in:
Adrian 2026-08-09 18:15:27 +02:00 committed by GitHub
parent 95fe7acc86
commit a0d1ad2001
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 2 deletions

View File

@ -305,6 +305,11 @@ class Response(object_ref):
:class:`~.TextResponse` provides a :meth:`~.TextResponse.follow_all`
method which supports selectors in addition to absolute/relative URLs
and Link objects.
.. caution:: Every returned request gets its own *meta* and
*cb_kwargs* dictionaries, but the values within them are shared.
Mutating one of those values, e.g. appending to a list, affects
all the returned requests.
"""
if not hasattr(urls, "__iter__"):
raise TypeError("'urls' argument must be an iterable")

View File

@ -276,6 +276,9 @@ class TextResponse(Response):
using the ``css`` or ``xpath`` parameters, this method will not produce requests for
selectors from which links cannot be obtained (for instance, anchor tags without an
``href`` attribute)
.. seealso:: :meth:`.Response.follow_all`, for a caution about mutable
*meta* and *cb_kwargs* values.
"""
arguments = [x for x in (urls, css, xpath) if x is not None]
if len(arguments) != 1:

View File

@ -15,8 +15,7 @@ logger = logging.getLogger(__name__)
class MetaCopyDetectionMiddleware(BaseSpiderMiddleware):
"""Warn when a spider yields a request with internal meta keys that should
not be copied from response.meta, or when two requests share the same meta
dict object.
not be copied from response.meta.
Each warning is emitted at most once per crawl.
"""