Staging instance, all changes can be removed at any time

Skip to content

backend: Prevent query exception when lister ids is empty

Without this, some cli call can just break because no lister is found [1]

swhscheduler@scheduler0:~$ swh scheduler -C /etc/softwareheritage/scheduler/listener-runner.yml origin send-to-celery golang
0 slots available in celery queue
0 visits to send to celery
Traceback (most recent call last):
  File "/usr/bin/swh", line 33, in <module>
    sys.exit(load_entry_point('swh.core==2.14.0', 'console_scripts', 'swh')())
  File "/usr/lib/python3/dist-packages/swh/core/cli/__init__.py", line 184, in main
    return swh(auto_envvar_prefix="SWH")
  File "/usr/lib/python3/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/lib/python3/dist-packages/swh/scheduler/cli/origin.py", line 214, in send_to_celery
    for task_dict in create_origin_task_dicts(origins, scheduler):
  File "/usr/lib/python3/dist-packages/swh/scheduler/utils.py", line 98, in create_origin_task_dicts
    for lister in scheduler.get_listers_by_id(list(map(str, lister_ids)))
  File "/usr/lib/python3/dist-packages/swh/core/db/common.py", line 73, in _meth
    return meth(self, *args, db=db, cur=cur, **kwargs)
  File "/usr/lib/python3/dist-packages/swh/scheduler/backend.py", line 176, in get_listers_by_id
    cur.execute(query, (tuple(lister_ids),))
  File "/usr/lib/python3/dist-packages/psycopg2/extras.py", line 251, in execute
    return super(RealDictCursor, self).execute(query, vars)
psycopg2.errors.SyntaxError: syntax error at or near ")"
LINE 3:               where id in ()

Related to swh/infra/sysadm-environment#4545 (closed)

Test Plan

Hot patched in staging and it's fine now.


Migrated from D8524 (view on Phabricator)

Merge request reports

Loading