-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unlike what doc states, --app does not behave like -A #4558
Comments
whats the status with celery 4.2.1? |
Exact same with v4.2.1 (windowlicker). |
There is in fact a behavioral difference that depends on arguments position:
|
do you have any suggested improvement in mind? |
Well, that I think it should behave the same whatever the order of arguments is. I struggled and lost a bit of time because I first chosed the way that does not work (you know, Murphy's law). I tried to look in the argparsing code of celery to see if I could patch it, but wasn't clear to me how it worked, hence opening the issue. If you point me to the right direction (like where it should be done, and probably how it is tested today), I may be able to submit a patch. |
We're adding both Line 299 in eeda186
They should be entirely interchangeable. We haven't done anything else to define that argument. The relevant test which verifies this passes (and you are welcome to run the tests yourself): celery/t/unit/bin/test_base.py Line 184 in f3ef0df
I cannot reproduce this behavior locally on my Linux machine. Unless you can provide me with new information on how to reproduce this bug (e.g. it only happens on OSX or some certain order of arguments) I think it's is safe to close this one. |
@thedrow Thanks for the infos. It does indeed appear with certain order of arguments, using "--app x" (not "--app=x", notice the lack of equal sign) before the celery subcommand (worker, inspect, ...). It is 100% reproductible on linux, here is how. I launch a brand new linux image (docker) running "python:3" official image. The image was run using
(edited for copypaste mistake) Minimalist, right ? Now run in this image:
Works as expected. Let's switch to
Note that it does work with I don't agree on the fact that it's "plain argparse". I think that the culprit code is somehow related to I understand the goal, but it does not work 100% with arguments as understood by Behaviour is 100% same on OSX and Linux. I tried to write an unit test but my lack of understanding the celery codebase (and especially, what the MockCommand does) made me fail at that. |
(note that this bug is probably also affecting all other global options passed before the command name and that have arguments, like Example:
|
Thank you for the analysis. This is indeed a bug and I am able to reproduce it as you said. I used |
I did see the "=" sign in answers, hence the small emphasis on not using it. Note that I'd gladly work on a fix, but the complexity added by the argparse-related hack to reorder arguments and the fact that for now, tests does not check cases with arguments before and after the subcommand makes me feel slightly uncomfortable about submitting a patch, as I don't know how to test it. However, I do understand why the hack exist, as this is a struggle I often have with argparse (having "global arguments" work both before and after subcommand). I think it's a UX defect of argparse, and I understand that celery want to work around it. But this is something that can really annoy users, especially users like me that only use celery every insert long period of time here (and Murphy's law forces me to use the only case that does not work, by default ...). If you can give a few pointers on how to test cases with arguments before and after the subcommand in the unit tests, I can give it a shot. It looks like the test you pointed me to skips argparsing, as MockCommand overrides
|
Just hit this issue too, with 4.4.6. It's indeed related to
Walking the historyIt was once a simple function: def remove_options_at_beginning(self, argv, index=0):
if argv:
while index < len(argv):
value = argv[index]
if value.startswith("--"):
pass
elif value.startswith("-"):
index += 1
else:
return argv[index:]
index += 1
return [] which already behaved differently for The trace to this function is, in my case:
Which looks strange to me is that |
While trying to fix it I discoverd the bug hit any command argument using two dashes and taking a value, for example:
vs
|
* FIX: -A and --args should behave the same. Closes #4558 The added test should fail like this, without this patch: AssertionError: assert 't.unit.bin.test_celery.APP' == 'worker' * Remove dead code. * Feel that this should be kept untouched.
Julien can you please check a regression report which might cause by the fix you provide for this issue? |
Sorry for the latency I was on holidays (I'm still until september). I think my commit should be reverted and this issue reopened, it, at least, "documented" something for future implementers, in the git log. Various things that broke should be added in the tests. Celery argument parsing is too complicated for me, I'm not willing to spend more time on it. I think Celery should slowly deprecate odd usages like giving subcommand arguments before the subcommand itself, it would simplify the code and indirectly close this issue. But I don't feel legitimate to push this, it's a long term process, as a lot of people and scripts (some of them hidden deep in docker images I bet) are relying on those odd orders and will break. |
let's come back from vacation! we will handle it after you are available |
* FIX: -A and --args should behave the same. Closes celery#4558 The added test should fail like this, without this patch: AssertionError: assert 't.unit.bin.test_celery.APP' == 'worker' * Remove dead code. * Feel that this should be kept untouched.
Steps to reproduce
celery --app foo *anything*
.Expected behavior
"-A foo" and "--app foo" to behave the same way.
Actual behavior
"-A foo" works, while "--app foo" just outputs the "celery usage" screen
Environment
The text was updated successfully, but these errors were encountered: