Skip to content

fix: keep a crawler's default statistics off a standalone Statistics' persist key - #4299

Merged
vladfrangu merged 4 commits into
apify:masterfrom
guerinnoah:fix/statistics-id-collision
Dec 1, 2026
Merged

vladfrangu merged 4 commits into
apify:masterfrom
guerinnoah:fix/statistics-id-collision

Conversation

@guerinnoah

Copy link
Copy Markdown
Contributor

A crawler without an explicit id gave its default Statistics the crawler's instance index as its id. A Statistics created without an id takes its number from a separate counter, and the crawler's default never advanced that counter. So a crawler and a standalone Statistics could end up with the same number and overwrite each other under the same CRAWLEE_CRAWLER_STATISTICS_{id} key, whichever of them was created first.

The crawler now passes its id to the default Statistics only when one was set. Otherwise the default takes the next number from the counter, like any other Statistics without an id, which is how 3.x numbered them. The first crawler still persists to CRAWLEE_CRAWLER_STATISTICS_0 unless a Statistics was created before it, and a crawler with an explicit id still persists under that id.

I didn't use the fix proposed in the issue (advancing the counter on every construction). It only covers a Statistics created after the crawler: one created before the first crawler would still take 0, the number the crawler uses too.

Side effect: an anonymous crawler created after one with an explicit id now persists to _0 instead of _1, as in 3.x.

Closes #4295

@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Oct 23, 2026
@barjin
barjin requested a review from vladfrangu November 3, 2026 13:38
@janbuchar
janbuchar self-requested a review November 9, 2026 09:15

@janbuchar janbuchar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Side effect: an anonymous crawler created after one with an explicit id now persists to _0 instead of _1, as in 3.x.

This should be (very briefly) mentioned in the upgrading guide

@vladfrangu
vladfrangu requested a review from janbuchar November 30, 2026 09:49

@janbuchar janbuchar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM I suppose

@janbuchar

Copy link
Copy Markdown
Contributor

The fix itself has been merged as part of #4487

…ollision

# Conflicts:
#	docs/upgrading/upgrading-v4/upgrading-v4.md
@vladfrangu
vladfrangu merged commit 06929f1 into apify:master Dec 1, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default crawler statistics can share a persist key with a standalone Statistics

3 participants