Page MenuHomeSoftware Heritage

backend: Prevent query exception when lister ids is empty
ClosedPublic

Authored by ardumont on Sep 23 2022, 9:50 AM.

Details

Summary

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 T4545

Test Plan

Hot patched in staging and it's fine now.

Diff Detail

Repository
rDSCH Scheduling utilities
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Build is green

Patch application report for D8524 (id=30701)

Rebasing onto b1afdab920...

Current branch diff-target is up to date.
Changes applied before test
commit 6d0b1d1e1ab5245e7b13513f1abbcee4bd85876b
Author: Antoine R. Dumont (@ardumont) <ardumont@softwareheritage.org>
Date:   Fri Sep 23 09:48:30 2022 +0200

    backend: Prevent query exception when lister ids is empty
    
    Related to T4545

See https://jenkins.softwareheritage.org/job/DSCH/job/tests-on-diff/561/ for more details.

vsellier added a subscriber: vsellier.

awesome thanks.

This revision is now accepted and ready to land.Sep 23 2022, 10:20 AM