Skip to content

Commit 0905964

Browse files
committed
refactor!: remove deprecated StatisticsState.crawler_runtime setter (#2315)
Removes the `StatisticsState.crawler_runtime` setter. The runtime is computed from the start and finish timestamps, so the setter only warned and threw the value away. Assigning to the property now raises `AttributeError`. The v2 upgrade guide has a short note about it. Closes: #1567 *✍️ Drafted by Claude Code*
1 parent 9cb7a84 commit 0905964

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

‎docs/06_upgrading/upgrading_to_v2.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ We drop support for Python 3.10, which reached its end of life in October 2026.
1212
## `Event` is a `StrEnum`
1313

1414
`Event` now subclasses `enum.StrEnum`. Calling `str()` on a member or formatting it in an f-string returns its value, for example `'systemInfo'`, where v1 returned `'Event.SYSTEM_INFO'`. Comparisons with plain strings work the same way as in v1.
15+
16+
## `StatisticsState.crawler_runtime` is read-only
17+
18+
`StatisticsState.crawler_runtime` is computed from the crawler's start and finish timestamps. In v1, assigning to it only emitted a `DeprecationWarning` and the value was ignored. In v2, the property has no setter, so an assignment raises `AttributeError`. Remove any such assignments.

‎src/crawlee/statistics/_models.py‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import json
4-
import warnings
54
from dataclasses import asdict, dataclass
65
from datetime import UTC, datetime, timedelta
76
from typing import TYPE_CHECKING, Annotated, Any
@@ -117,17 +116,6 @@ def crawler_runtime(self) -> timedelta:
117116
return self._runtime_offset + finished_at - self.crawler_last_started_at
118117
return self._runtime_offset
119118

120-
@crawler_runtime.setter
121-
def crawler_runtime(self, value: timedelta) -> None:
122-
# Setter for backwards compatibility only, the crawler_runtime is now computed_field, and can't be set manually.
123-
# To be removed in v2 release https://github.com/apify/crawlee-python/issues/1567
124-
warnings.warn(
125-
f"Setting 'crawler_runtime' is deprecated and will be removed in a future version."
126-
f' Value {value} will not be used.',
127-
DeprecationWarning,
128-
stacklevel=2,
129-
)
130-
131119
@computed_field(alias='crawlerRuntimeMillis')
132120
def crawler_runtime_for_serialization(self) -> timedelta:
133121
if self.crawler_last_started_at:

0 commit comments

Comments
 (0)