Skip to content
Snippets Groups Projects

Add a small hint when tasks are called with missing keywords

1 unresolved thread

Calling swh scheduler task add load-git https://example.org/repository.git instead of swh scheduler task add load-git url=https://example.org/repository.git will result in a confusing TypeError being raised by the scheduler.

This change adds a small note to the TypeError pointing at the arguments of swh scheduler task add.

This uses the BaseException.add_note method which was introduced in Python 3.11.

Sadly, I was not able to understand where to plug a test for this.

The result looks like:

ERROR    celery.app.trace:trace.py:270 Task swh.scheduler.tests.tasks.keyword[c6764342-bdda-4d92-9e2d-11e6119ae49b] raised unexpected: TypeError("keyword() missing 1 required keyword-only argument: 'keyword'")
Traceback (most recent call last):
  File "/home/lunar/.pyenv/versions/swh3.11/lib/python3.11/site-packages/celery/app/trace.py", line 477, in trace_task
    R = retval = fun(*args, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^
  File "/home/lunar/Documents/SWH/swh-environment/swh-scheduler/build/__editable__.swh.scheduler-1.13.1.dev2+g869514d.d20231211-py3-none-any/swh/scheduler/task.py", line 67, in __call__
    raise e
  File "/home/lunar/Documents/SWH/swh-environment/swh-scheduler/build/__editable__.swh.scheduler-1.13.1.dev2+g869514d.d20231211-py3-none-any/swh/scheduler/task.py", line 62, in __call__
    result = super().__call__(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lunar/.pyenv/versions/swh3.11/lib/python3.11/site-packages/celery/app/task.py", line 411, in __call__
    return self.run(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: keyword() missing 1 required keyword-only argument: 'keyword'
Would you have forgotten to write the keywords when calling `swh scheduler task add`?

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
58 58 self.statsd.increment("swh_task_called_count")
59 59 self.statsd.gauge("swh_task_start_ts", ts())
60 60 with self.statsd.timed("swh_task_duration_seconds"):
61 try:
61 62 result = super().__call__(*args, **kwargs)
63 except TypeError as e:
64 e.add_note(
65 "Would you have forgotten to write the keywords when calling "
66 "`swh scheduler task add`?"
  • Comment on lines +65 to +66
    Suggested change
    65 "Would you have forgotten to write the keywords when calling "
    66 "`swh scheduler task add`?"
    65 "Check the keyword arguments passed to "
    66 "`swh scheduler task add`."

    ?

  • Please register or sign in to reply
  • @lunar Now that we're using 3.10 in production, maybe the optional part @olasd mention is no longer useful (I don't know if the "lower" is strict or not in his sentence ;).

    I've iterated over olasd's suggestion as an inline suggested change in the code. Note that i've just added the "keyword" prefix.

    Almost ready to be merged if you wanna have an extra push

  • Please register or sign in to reply
    Loading