{"record":{"id":"0e41b58d7c0044cb","repo":"scrapy/scrapy","slug":"request-priority-not-an-integer-priority-r","errorCode":null,"errorMessage":"Request priority not an integer: {priority!r}","messagePattern":"Request priority not an integer: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"scrapy/http/request/__init__.py","lineNumber":149,"sourceCode":"        | Iterable[tuple[str | bytes, Any]]\n        | None = None,\n        body: bytes | str | None = None,\n        cookies: CookiesT | None = None,\n        meta: dict[str, Any] | None = None,\n        encoding: str = \"utf-8\",\n        priority: int = 0,\n        dont_filter: bool = False,\n        errback: Callable[[Failure], Any] | None = None,\n        flags: list[str] | None = None,\n        cb_kwargs: dict[str, Any] | None = None,\n    ) -> None:\n        self._encoding: str = encoding  # this one has to be set first\n        self.method: str = str(method).upper()\n        self._meta: dict[str, Any] | None = dict(meta) if meta else None\n        self._set_url(url)\n        self._set_body(body)\n        if not isinstance(priority, int):\n            raise TypeError(f\"Request priority not an integer: {priority!r}\")\n\n        #: Default: ``0``\n        #:\n        #: Value that the :ref:`scheduler <topics-scheduler>` may use for\n        #: request prioritization.\n        #:\n        #: Built-in schedulers prioritize requests with a higher priority\n        #: value.\n        #:\n        #: Negative values are allowed.\n        self.priority: int = priority\n\n        if not (callable(callback) or callback is None):\n            raise TypeError(\n                f\"callback must be a callable, got {type(callback).__name__}\"\n            )\n        if not (callable(errback) or errback is None):\n            raise TypeError(f\"errback must be a callable, got {type(errback).__name__}\")","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/scrapy/scrapy/blob/06af687662112027b4482d31e2714a3cf280a91f/scrapy/http/request/__init__.py#L131-L167","documentation":"Request.__init__ raises TypeError when the priority argument is not an int (bool counts as int and passes; floats and strings do not). Priority is used directly by built-in schedulers for ordering and must be an exact integer to keep comparisons and deque ordering deterministic; a bool like True would silently work as 1, but 1.0 or '1' fail this guard before any scheduling happens.","triggerScenarios":"Request(url, priority=1.5) or priority=float(some_setting); priority computed as '10' from a string config; passing a numpy integer type (not a Python int, so isinstance fails); templated code where priority comes from an untyped source like CSV/JSON.","commonSituations":"Priority read from settings/env as string and not converted; float arithmetic ('base + 0.5 * depth') feeding priority; interop with libraries returning non-int numerics (numpy.int64 is actually fine on CPython but Decimal/float are not).","solutions":["Coerce to int at the call site: priority=int(priority) after validating the value","If you need fractional ordering, scale to integers (e.g. priority * 100 as int) since built-in schedulers only accept int","Cast external config once at load: priority = int(settings['PRIORITY'])","Add a unit assertion in helpers that build requests from untrusted data: isinstance(priority, int)"],"exampleFix":"# before\nRequest(url, priority=0.5)      # TypeError\nRequest(url, priority='10')     # TypeError\n\n# after\nRequest(url, priority=1)\nRequest(url, priority=int('10'))\n# scaled fractional ordering:\nRequest(url, priority=int(0.5 * 100))","handlingStrategy":"validation","validationCode":"if not isinstance(priority, int):\n    priority = int(priority)  # or raise with context\nRequest(url, priority=priority)","typeGuard":"def is_valid_priority(p) -> bool:\n    return isinstance(p, int) and not isinstance(p, bool) or isinstance(p, bool)","tryCatchPattern":"null","preventionTips":["Convert numeric config values to int once at load time","Use integer scaling for fractional priorities","Assert types in request-builder helpers fed by external data"],"tags":["request","priority","typeerror","validation"],"backgroundTag":null,"analyzedSha":"06af687662112027b4482d31e2714a3cf280a91f","analyzedAt":"2026-08-15T00:21:48.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}