cloudflare / cloudflare/cloudflare-docs

Example given for scheduled handler in python have positional arguments that are None.

Open
#30,383 1 comment 0 reactions 10 assignees Claimed by @WalshyDev View on GitHub
content:edit documentation product:workers product:workflows stale
Dominant language
MDX
Stars
5.2k
Forks
16.7k
Avg merge
2d 6h
Merged PRs (30d)
337

Description

### Existing documentation URL(s)

- https://developers.cloudflare.com/workers/runtime-apis/handlers/scheduled/#syntax

In this section, the `scheduled` method takes 4 positional arguments. However, in reality, `env` and `ctx` are both None, and other [doc](https://developers.cloudflare.com/workflows/python/python-workers-api/#create-an-instance-via-binding) (although this is for fetch) suggested that I should access the context and environment variables via `self.ctx` and `self.env`, which does work.

### What changes are you suggesting?

I believe this example needs to be modified, including the section below where it generally describes what each arguments are. However, they are written in a manner that is programming language agnostic, so there needs to be clarification for the pythons case that those values are available under `self` and not positional arguments.

I think example could be something similar to [this example](https://github.com/cloudflare/python-workers-examples/blob/main/08-cron/src/entry.py) in cloudflare/python-worker-examples repo

However, this example is faulty as scheduled still receiving four positional arguments, which I wonder if it is bug.

### Additional information

If I run the given [example](https://github.com/cloudflare/python-workers-examples/blob/15545c578813b70bf2c47d4593c2faf8191ba226/08-cron/src/entry.py#L6) in the cloudflare/python-worker-examples repo, it would throw this error saying wrong number of arguments.

Image

if you run a code that is similar to the code block I raised a ticket about, both `ctx` and `env` are `None`

```python
from workers import WorkerEntrypoint

class Default(WorkerEntrypoint):
async def scheduled(self, controller, env, ctx):
print(env, ctx)
```

The above code yields the below

Image

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.