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

TypeError: Tasks must have an initial Context argument! #362

Closed
deckar01 opened this issue Jun 17, 2016 · 6 comments
Closed

TypeError: Tasks must have an initial Context argument! #362

deckar01 opened this issue Jun 17, 2016 · 6 comments

Comments

@deckar01
Copy link

Upgrading from v0.12.2 to v0.13.0 gives causes my task to error with TypeError: Tasks must have an initial Context argument!.

0ce6220...7f8fdc3#diff-a2c23243533cad12946af2f1122bb4ebR144

$ invoke test
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/invoke/tasks.py", line 141, in argspec
    context_arg = arg_names.pop(0)
IndexError: pop from empty list
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.4.2/bin/invoke", line 11, in <module>
    sys.exit(program.run())
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/invoke/program.py", line 269, in run
    self._parse(argv)
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/invoke/program.py", line 325, in _parse
    self.load_collection()
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/invoke/program.py", line 473, in load_collection
    coll = loader.load(coll_name) if coll_name else loader.load()
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/invoke/loader.py", line 53, in load
    module = imp.load_module(name, fd, path, desc)
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/imp.py", line 235, in load_module
    return load_source(name, filename, file)
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/imp.py", line 171, in load_source
    module = methods.load()
  File "<frozen importlib._bootstrap>", line 1220, in load
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/travis/build/deckar01/marshmallow/tasks.py", line 27, in <module>
    @task
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/invoke/tasks.py", line 267, in task
    return Task(args[0], **kwargs)
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/invoke/tasks.py", line 58, in __init__
    self.positional = self.fill_implicit_positionals(positional)
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/invoke/tasks.py", line 149, in fill_implicit_positionals
    args, spec_dict = self.argspec(self.body)
  File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/invoke/tasks.py", line 144, in argspec
    raise TypeError("Tasks must have an initial Context argument!")
TypeError: Tasks must have an initial Context argument!
@kynikos
Copy link

kynikos commented Jun 19, 2016

I'm very new to Invoke (10 minutes experience), but for those like me running into this bug, a temporary workaround is to add a positional argument to the tasks, e.g.:

@task
def build(ctx):
    print("Building!")

@deckar01
Copy link
Author

Thanks for your fresh eyes @kynikos. 👀

I also had to pass the context object along to child tasks.

@task
def build(ctx):
    foo(ctx)

@task
def foo(ctx):
    print("Building!")

It is not so much a temporary work around as it is using the 0.13 API for invoke. I will leave this issue open for now and suggest documenting breaking changes in a change log or upgrade notes.

@deckar01
Copy link
Author

deckar01 commented Jun 19, 2016

It is worth noting that the readme example shows calling run on the context instance, but the library still allows importing invoke.run and not using the context object.

It would be nice if the task implementation created a new context instance for you when initializing a task and when calling a subtask.

@darioblanco
Copy link

darioblanco commented Jun 19, 2016

Hi @deckar01

In the Changelog for 0.13.0 you can see that [Feature] #114 has a backwards incompatible change. Now, all tasks are contextualized and ctask is not needed anymore.

It also broke my invoke program, thanks to unit testing, I could easily discover this change and fix it :)

You can check the new documentation , you basically already fixed the problem

@deckar01
Copy link
Author

Since i'ts in the change log and no backwards compatibility is being enforced pre 1.0.0, I will close this issue. I will have to be more strict with my version pinning in the future.

@Zeioth
Copy link

Zeioth commented Jan 14, 2017

It's really neccesary making ctx a required argument? I'm not using it in most on my methods so I get

"parameter 'ctx' value is not used"

lint error all the time.

EDIT

I've found this workaround to silence the linter error only for ctx.

@task
def create_application(ctx):
    del ctx

    # ...

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

4 participants