Repository: celery/celery

Issue:
Events command always fails when camera is specified
<!--
Please fill this template entirely and do not erase parts of it.
We reserve the right to close without a response
bug reports which are incomplete.
-->
# Checklist
<!--
To check an item on the list replace [ ] with [x].
-->
- [x] I have verified that the issue exists against the `master` branch of Celery.
- [ ] This has already been asked to the [discussion group](https://groups.google.com/forum/#!forum/celery-users) first.
- [x] I have read the relevant section in the
  [contribution guide](http://docs.celeryproject.org/en/latest/contributing.html#other-bugs)
  on reporting bugs.
- [x] I have checked the [issues list](https://github.com/celery/celery/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-label%3A%22Category%3A+Documentation%22)
  for similar or identical bug reports.
- [x] I have checked the [pull requests list](https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22PR+Type%3A+Bugfix%22+-label%3A%22Category%3A+Documentation%22)
  for existing proposed fixes.
- [x] I have checked the [commit log](https://github.com/celery/celery/commits/master)
  to find out if the bug was already fixed in the master branch.
- [x] I have included all related issues and possible duplicate issues
  in this issue (If there are none, check this box anyway).

## Mandatory Debugging Information

- [x] I have included the output of ``celery -A proj report`` in the issue.
    (if you are not able to do this, then at least specify the Celery
     version affected).
- [x] I have verified that the issue exists against the `master` branch of Celery.
- [x] I have included the contents of ``pip freeze`` in the issue.
- [x] I have included all the versions of all the external dependencies required
  to reproduce this bug.

## Optional Debugging Information
<!--
Try some of the below if you think they are relevant.
It will help us figure out the scope of the bug and how many users it affects.
-->
- [ ] I have tried reproducing the issue on more than one Python version
  and/or implementation.
- [ ] I have tried reproducing the issue on more than one message broker and/or
  result backend.
- [ ] I have tried reproducing the issue on more than one version of the message
  broker and/or result backend.
- [ ] I have tried reproducing the issue on more than one operating system.
- [ ] I have tried reproducing the issue on more than one workers pool.
- [ ] I have tried reproducing the issue with autoscaling, retries,
  ETA/Countdown & rate limits disabled.
- [ ] I have tried reproducing the issue after downgrading
  and/or upgrading Celery and its dependencies.

## Related Issues and Possible Duplicates
<!--
Please make sure to search and mention any related issues
or possible duplicates to this issue as requested by the checklist above.

This may or may not include issues in other repositories that the Celery project
maintains or other repositories that are dependencies of Celery.

If you don't know how to mention issues, please refer to Github's documentation
on the subject: https://help.github.com/en/articles/autolinked-references-and-urls#issues-and-pull-requests
-->

#### Related Issues

- None

#### Possible Duplicates

- None

## Environment & Settings
<!-- Include the contents of celery --version below -->
**Celery version**: 5.05 and master (2411504f4164ac9acfa20007038d37591c6f57e5)
<!-- Include the output of celery -A proj report below -->
<details>
<summary><b><code>celery report</code> Output:</b></summary>
<p>

```
software -> celery:5.1.0b2 (singularity) kombu:5.1.0b1 py:3.9.5
            billiard:3.6.4.0 py-amqp:5.0.6
platform -> system:Darwin arch:64bit
            kernel version:20.4.0 imp:CPython
loader   -> celery.loaders.app.AppLoader
settings -> transport:amqp results:disabled

deprecated_settings: None
```

</p>
</details>

# Steps to Reproduce

## Required Dependencies
<!-- Please fill the required dependencies to reproduce this issue -->
* **Minimal Python Version**: Unknown, tested on 3.9
* **Minimal Celery Version**: Unknown, tested on 5.05 and master
* **Minimal Kombu Version**: N/A 
* **Minimal Broker Version**: N/A
* **Minimal Result Backend Version**: N/A
* **Minimal OS and/or Kernel Version**: N/A
* **Minimal Broker Client Version**: N/A
* **Minimal Result Backend Client Version**: N/A

### Python Packages
<!-- Please fill the contents of pip freeze below -->
<details>
<summary><b><code>pip freeze</code> Output:</b></summary>
<p>

```
amqp==5.0.6
billiard==3.6.4.0
celery @ git+https://github.com/celery/celery.git@2411504f4164ac9acfa20007038d37591c6f57e5
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.1.6
kombu==5.1.0b1
prompt-toolkit==3.0.18
pytz==2021.1
six==1.16.0
vine==5.0.0
wcwidth==0.2.5
```

</p>
</details>

### Other Dependencies
<!--
Please provide system dependencies, configuration files
and other dependency information if applicable
-->
<details>
<p>
N/A
</p>
</details>

## Minimally Reproducible Test Case
<!--
Please provide a reproducible test case.
Refer to the Reporting Bugs section in our contribution guide.

We prefer submitting test cases in the form of a PR to our integration test suite.
If you can provide one, please mention the PR number below.
If not, please attach the most minimal code example required to reproduce the issue below.
If the test case is too large, please include a link to a gist or a repository below.
-->

<details>
<p>

`app.py`:

```python
import celery

app = celery.Celery()
```

`camera.py`:

```python
from celery.events.snapshot import Polaroid

class Camera(Polaroid):
    def on_shutter(self, _):
        print("Hello!")
```

</p>
</details>

# Expected Behavior
<!-- Describe in detail what you expect to happen -->

The following command should (attempt to) start the event camera:

```
$ celery -A app events -c camera
...
ModuleNotFoundError: No module named 'camera'
```

(The bug is independent of whether the module `camera` exists.)

# Actual Behavior
<!--
Describe in detail what actually happened.
Please include a backtrace and surround it with triple backticks (```).
In addition, include the Celery daemon logs, the broker logs,
the result backend logs and system logs below if they will help us debug
the issue.
-->

A backtrace is produced:

```
Traceback (most recent call last):
  File "/Users/user/Desktop/tmp/venv/bin/celery", line 8, in <module>
    sys.exit(main())
  File "/Users/user/Desktop/tmp/venv/lib/python3.9/site-packages/celery/__main__.py", line 15, in main
    sys.exit(_main())
  File "/Users/user/Desktop/tmp/venv/lib/python3.9/site-packages/celery/bin/celery.py", line 213, in main
    return celery(auto_envvar_prefix="CELERY")
  File "/Users/user/Desktop/tmp/venv/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/user/Desktop/tmp/venv/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/user/Desktop/tmp/venv/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/user/Desktop/tmp/venv/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/user/Desktop/tmp/venv/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/user/Desktop/tmp/venv/lib/python3.9/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/user/Desktop/tmp/venv/lib/python3.9/site-packages/celery/bin/base.py", line 132, in caller
    return f(ctx, *args, **kwargs)
  File "/Users/user/Desktop/tmp/venv/lib/python3.9/site-packages/celery/bin/events.py", line 90, in events
    return _run_evcam(camera, app=app, freq=frequency, maxrate=maxrate,
  File "/Users/user/Desktop/tmp/venv/lib/python3.9/site-packages/celery/bin/events.py", line 37, in _run_evcam
    return cam()
TypeError: evcam() got an unexpected keyword argument 'executable'
```



Discussion:
Hey @alexpearce :wave:,
Thank you for opening an issue. We will get back to you as soon as we can.
Also, check out our [Open Collective](https://opencollective.com/celery) and consider backing us - every little helps!

We also offer priority support for our sponsors.
If you require immediate assistance please consider sponsoring us.

The problem is that the [`events` command](https://github.com/celery/celery/blob/2411504f4164ac9acfa20007038d37591c6f57e5/celery/bin/events.py#L83) [derives its arguments](https://github.com/celery/celery/blob/2411504f4164ac9acfa20007038d37591c6f57e5/celery/bin/events.py#L51) from [`CeleryDaemonCommand`](https://github.com/celery/celery/blob/8ebcce1523d79039f23da748f00bec465951de2a/celery/bin/base.py#L171), and that includes an `--executable` flag. This gets propagated through `**kwargs` until it reaches [`evcam`](https://github.com/celery/celery/blob/2411504f4164ac9acfa20007038d37591c6f57e5/celery/events/snapshot.py#L86) which does not have an `executable` argument.

This patch allows the execution to continue:

```diff
diff --git a/celery/events/snapshot.py b/celery/events/snapshot.py
index 813b8db5c..d611cb280 100644
--- a/celery/events/snapshot.py
+++ b/celery/events/snapshot.py
@@ -84,7 +84,8 @@ class Polaroid:
 
 
 def evcam(camera, freq=1.0, maxrate=None, loglevel=0,
-          logfile=None, pidfile=None, timer=None, app=None):
+          logfile=None, pidfile=None, timer=None, app=None,
+          executable=None):
     """Start snapshot recorder."""
     app = app_or_default(app)
```

I would open a PR straight away but I'm not sure if the value of `executable` should actually be used by `evcam` for something.
Just make the method accept `**kwargs`. I think that should work.
Sounds reasonable, as long as you don't mind an unused argument.

Shall I open a PR with that?
Yeah. Go ahead.

Resolving patch:
diff --git a/celery/events/snapshot.py b/celery/events/snapshot.py
--- a/celery/events/snapshot.py
+++ b/celery/events/snapshot.py
@@ -84,7 +84,8 @@ def __exit__(self, *exc_info):
 
 
 def evcam(camera, freq=1.0, maxrate=None, loglevel=0,
-          logfile=None, pidfile=None, timer=None, app=None):
+          logfile=None, pidfile=None, timer=None, app=None,
+          **kwargs):
     """Start snapshot recorder."""
     app = app_or_default(app)
 


Test patch: