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 collection name validation #100

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/reference/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ INCREMENTAL_CRAWL_COLLECTION_NAME
:attr:`~zyte_spider_templates.spiders.article.ArticleSpiderParams.incremental_collection_name`
command-line parameter instead of this setting.

.. note::
Only ASCII alphanumeric characters and underscores are allowed.

Default: `<The current spider's name>_incremental`.
The current spider's name here will be virtual spider's name, if it's a virtual spider;
Expand Down
8 changes: 6 additions & 2 deletions tests/test_article.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,19 @@ def test_metadata():
"type": "boolean",
},
"incremental_collection_name": {
"anyOf": [{"type": "string"}, {"type": "null"}],
"anyOf": [
{"type": "string", "pattern": "^[a-zA-Z0-9_]+$"},
{"type": "null"},
],
"default": None,
"description": "Name of the Zyte Scrapy Cloud Collection used during an incremental crawl."
"By default, a Collection named after the spider (or virtual spider) is used, "
"meaning that matching URLs from previous runs of the same spider are skipped, "
"provided those previous runs had `incremental` argument set to `true`."
"Using a different collection name makes sense, for example, in the following cases:"
"- different spiders share a collection."
"- the same spider uses different collections (e.g., for development runs vs. production runs).",
"- the same spider uses different collections (e.g., for development runs vs. production runs). "
"Only ASCII alphanumeric characters and underscores are allowed in the collection name.",
"title": "Incremental Collection Name",
},
"crawl_strategy": {
Expand Down
4 changes: 3 additions & 1 deletion zyte_spider_templates/spiders/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ class IncrementalParam(BaseModel):
"provided those previous runs had `incremental` argument set to `true`."
"Using a different collection name makes sense, for example, in the following cases:"
"- different spiders share a collection."
"- the same spider uses different collections (e.g., for development runs vs. production runs)."
"- the same spider uses different collections (e.g., for development runs vs. production runs). "
"Only ASCII alphanumeric characters and underscores are allowed in the collection name."
),
default=None,
pattern="^[a-zA-Z0-9_]+$",
)


Expand Down