Repository navigation
feat!: Persist sessions, statistics and sitemap state by default - #2539
Conversation
| max_buffer_size: int = 200, | ||
| persist_state_key: str | None = None, | ||
| persistence_enabled: bool = True, | ||
| persist_state_key: str = 'CRAWLEE_SITEMAP_REQUEST_LOADER_STATE', |
There was a problem hiding this comment.
Suggestion: persist_state_key=None meant no persistence in v1. Now it reaches the storage layer, and persist_state() fails with TypeError: quote_from_bytes() expected bytes, which doesn't point to the cause. Raise a ValueError for None that points to persistence_enabled=False.
✍️ Drafted by Claude Code
There was a problem hiding this comment.
It's covered in the upgrade guide, and a type checker flags the wrong type right away. I don't think it's worth adding a runtime error.
| self._request_manager = request_manager | ||
| self._session_pool = self._own_or_borrow(session_pool, SessionPool) | ||
| self._session_pool = self._own_or_borrow( | ||
| session_pool, lambda: SessionPool(persist_state_kvs_factory=self.get_key_value_store) |
There was a problem hiding this comment.
Note: _pause_by_event (_basic_crawler.py:1064) saves only the statistics after the migration pause. Session changes made by requests that finish during the pause are lost, and every crawler's pool now persists. Crawlee JS has the same gap, so this can be a follow-up issue in both repos.
✍️ Drafted by Claude Code
There was a problem hiding this comment.
Yes, let's do this in a separate PR.
There was a problem hiding this comment.
Opened #2552 for it.
✍️ Drafted by Claude Code
104a14a to
f472ad0
Compare
f472ad0 to
c57adc8
Compare
Description
Statistics,SessionPool,DefaultRenderingTypePredictorandSitemapRequestLoaderpersist their state by default. The session pool and the predictor that a crawler creates, and the default statistics ofAdaptivePlaywrightCrawler, persist to the crawler's key-value store, like its default statistics. For that,SessionPoolandDefaultRenderingTypePredictortake a newpersist_state_kvs_factory. The default statistics ofAdaptivePlaywrightCrawlernow also get theidyou pass to the crawler, the same as those of the other crawlers.SitemapRequestLoaderstores its state underCRAWLEE_SITEMAP_REQUEST_LOADER_STATEunless it gets apersist_state_key, andpersistence_enabled=Falseturns persistence off.Merge after #2536 reaches v2, which fixes restoring the predictor's state.
Issues
SessionPoolpersistence by default #2310Testing
id, and that the statistics of the sub crawlers don't persist.✍️ Drafted by Claude Code