Skip to content

Reject empty IDs and invalid numeric arguments when the client is built #1178

Description

@vdusek

Resource getters accept any string. An empty ID fails only when the first request builds its URL: to_path_segment('') raises ValueError('"" cannot be used as a URL path segment.') (_utils/http.py#L50-L51, via _resource_client.py#L76-L82). The error appears far from the code that passed the empty ID and does not name the argument.

client.user('') does not fail at all. UserClient uses resource_id or 'me' (user.py#L33-L44), so client.user(os.environ.get('USER_ID', '')) silently reads the token owner's account.

Most numeric arguments are not checked either: a negative limit or offset, or a negative retry delay or timeout on the client, is passed on as is. Only max_retries is validated, by #1142.

The JS client validates arguments with zod before any request: resourceIdSchema = z.string().min(1) on root getters including user() (apify_client.ts#L83, #L577-L578), versionNumberSchema and envVarNameSchema on nested getters (actor.ts#L61, actor_version.ts#L13), and min(0) / nonnegative() on limits and client options (utils.ts#L368-L370, http_clients/base.ts#L57-L62).

Expected behavior

Getters raise ValueError naming the argument when an ID is empty, at construction time. user('') raises, and only user() / user(None) means the current user. Client options (retry delays, timeouts) and pagination arguments (limit, offset) reject negative values. Request queue inputs are covered by #1093.

✍️ Drafted by Claude Code

Activity

  1. added this to the 4.0 milestone on Oct 30, 2026
  2. added
    enhancementNew feature or request.
    t-toolingIssues with this label are in the ownership of the tooling team.
    on Oct 30, 2026
  3. added theissue type on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions