Skip to content
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

Can not pass async() non-core functions #178

Closed
davewilliamstx opened this issue Jun 29, 2016 · 3 comments
Closed

Can not pass async() non-core functions #178

davewilliamstx opened this issue Jun 29, 2016 · 3 comments

Comments

@davewilliamstx
Copy link

davewilliamstx commented Jun 29, 2016

I have views.py and tasks.py in my project folder.

I have the following in views.py:

# views.py
def TestAsync(request):
    from django_q.tasks import async
    import tasks

    async('tasks.hi', 'Hooray!')

    return HttpResponseRedirect('blah')

and tasks.py is:

# tasks.py
def hi(string_to_print):
    print string_to_print

When I hit the url I have wired to call my TestAsync view, I get the following error:

'module' object has no attribute 'hi'

I am able, however, to get the email examples from the django-q docs working, among other examples that use functions from django core/python built-ins. I've tried passing the function to async() with and without quotes, tried putting the 'hi' function right in the view, and every importing scheme I can think of...I still get the same error.

I have a feeling that this might be an error caused my my lack of understanding on what constitutes an acceptable function to pass to async() - however on the off chance it's a bug I wanted to drop a note here.

If it's my fault, perhaps it will help others to have a lower-level explanation of what async() expects from it's functions?

@Koed00
Copy link
Owner

Koed00 commented Jun 29, 2016

You need to point to tasks.py with it's full path, which would include the project or root,
i.e. 'myapp.tasks.hi'.
This is because you're not restricted to executing only local functions.

If you had imported myapp.tasks in views.py, you could have pointed to it directly without the quotes.
The quoted approach however, is more safe.

@davewilliamstx
Copy link
Author

davewilliamstx commented Jun 29, 2016

I quickly tried adding the import from tasks import hi to the view, and then calling it directly, ie: async(hi, 'Hooray!') and I still get: 'module' object has no attribute 'hi'. Also tried passing the full path in quotes, no dice.

I really hope I'm not just doing something dumb, but I really think this should be working.

@davewilliamstx
Copy link
Author

As I suspected, it was me being dumb. Import redundancies in my views.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants