-
-
Notifications
You must be signed in to change notification settings - Fork 795
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
fix(tasks): fix error caused by relative import #1123
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand what is broken and that you are fixing. That task works as designed when using celery-beat. It works fine relative as it is part of the package. If you are not using celery-beat you should never invoke that code but instead directly call the cleartokens management command or invoke the clear_expired function
Closing as not applicable. |
I first saw this failing in production running inside celery. From Sentry: My example was to illustrate what's going on. But Regardless, the reason why the import is failing is because |
clear_tokens works as designed for use with celery-beat. I've tested it as such even though I don't use celery. It is not "regular" function as it is preceded by the celery |
@n2ygk why are you arguing it works as indended when I just offered proof that it doesn't, and even upon reviewing the code it becomes clear the import can't possibly work since it looks up the function outside of the package? |
Good question. So how come it worked for me and the original contributor @Natureshadow? Can you please help me out here and document how this is supposed to be configured with celery? I had asked @Natureshadow to do so but he just provided a link so I configured celery in a test app as best I could and didn't see any errors and that the task showed up in the django admin intervface. I suspect that the @shared_task decorator is changing the relative path location somehow but it's a bit over my head when reading it. Perhaps you can share a full sample app configuration that demonstrates the problem since it is not reproducible given this report alone and I frankly don't have unlimited time or knowledge to debug this. Cutting and pasting an error message without context is not enough. Given the other conflict with Huey #1114 I'm seriously considering reverting #1070 and leaving it up to someone to document how to add a Celery or Huey autoloaded tasks rather than including it in this package. |
Codecov Report
@@ Coverage Diff @@
## master #1123 +/- ##
=======================================
Coverage 96.62% 96.62%
=======================================
Files 32 32
Lines 1806 1806
=======================================
Hits 1745 1745
Misses 61 61
Continue to review full report at Codecov.
|
I don't think it did, really. I don't think you're liars either, but I checked #1070 and I see no proof it ever worked. Both you and @Natureshadow confirm the task is discovered, but none of you attested it actually ran. For example, at one point you're saying:
Detective work aside, in my experience with Celery I'd say simply importing the task and running it inside the shell ought to do it. [unbound] celery tasks are regular functions and can be called directly like any other function. Initially I started writing a smoke test, but I was faced with the choice of adding celery to the requirements or manipulating
But an alternative that would work as a smoke test would be to move the import statement at the top of the file. If there was an issue it would fail a lot sooner. I don't have experience with Huey. Regardless, personally I'm ok with reverting the original commit if it's causing problems. |
You will note that the import statement is inside the function definition not top-level in the tasks.py file. As such, it is not executed in the context of importing tasks.py but in the context of the decorator function for which the function definition is an argument. |
@n2ygk I reported a bug, showed proof of it and offered instructions to reproduce it, showed there was no proof that it ever worked, and offered to fix it. But rather than listening and possibly executing the code, it seems to me you're looking to argue and trying to be right or something like that. Whatever it is, it's not helping advance this conversation and not making the celery task run either. As such, I'll take a step back until we can have a reasonable conversation. Do let me know if you’re willing to do that. Luckily, in my project I'm not using celery’s autodiscover feature, so I'll set up a custom task that imports |
@alexei I asked you to provide an example that reproduces the bug in context. You did not. |
@n2ygk I showed you a screenshot with the error in production running in celery beat, and offered simple steps to reproduce it in the shell. Calling an unbound celery task directly is reasonable use. That said, I think I did my part of the deal. Besides, the error literally says you're importing from the outside of the package and the extra dots confirm it. If you don't connect the dots, there's nothing I can do about it. |
@alexei With tremendous amounts of egg on my face, I have connected the dots and apologize profusely. It seems @Natureshadow supplied an untested PR #1070. I was sticking by his word over yours. That was a mistake. I've configured Celery and reproduced the error and applied your fix and have documented how to use it here. I'll be reverting #1070 and documenting how to do instead add the |
Apology accepted. I appreciate your looking into this. What do you think about documenting the |
See #1128 |
@alexei PS: that dot-tutorial is just my sandbox. As you can see now at https://django-oauth-toolkit--1128.org.readthedocs.build/en/1128/tutorial/tutorial.html I've attempted to document this. Please feel free to review if you have the time. |
Both look fine by me 👍 |
Description of the Change
Running
oauth2_provider.tasks.clear_tokens
results in an error e.g.:This update fixes the import path.
Checklist
CHANGELOG.md
updated (only for user relevant changes)AUTHORS