So, I have code like this...
~~~
@app.route('/auto_thing', methods=['POST'], cors=True)
def index():
#Stuff happens in here
@app.route('/full_thing', methods=['POST'], cors=True)
def index():
stuff = 123
~~~
When I run chalice deploy I get a KeyError: 'stuff'. There is literally nothing else in the function for the full_thing endpoint at this point.
What in the world is going on here? How do I fix this so I can deploy?
Full stack trace:
~
Traceback (most recent call last):
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\cli__init__.py", line 384, in main
return cli(obj={})
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\click\core.py", line 716, in __call__
return self.main(args, *kwargs)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\click\core.py", line 696, in main
rv = self.invoke(ctx)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\click\core.py", line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\click\core.py", line 889, in invoke
return ctx.invoke(self.callback, *ctx.params)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\click\core.py", line 534, in invoke
return callback(args, *kwargs)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\click\decorators.py", line 17, in new_func
return f(get_current_context(), *args, *kwargs)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\cli__init__.py", line 166, in deploy
deployed_values = d.deploy(config, chalice_stage_name=stage)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\deploy\deployer.py", line 346, in deploy
return self._deploy(config, chalice_stage_name)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\deploy\deployer.py", line 356, in _deploy
self._build_stage.execute(config, resources)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\deploy\deployer.py", line 721, in execute
step.handle(config, resource)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\deploy\deployer.py", line 644, in handle
handler(config, resource)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\deploy\deployer.py", line 706, in handle_autogeniampolicy
policy = self._policy_gen.generate_policy(config)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\policy.py", line 80, in generate_policy
app_policy = policy_from_source_code(app_source)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\policy.py", line 24, in policy_from_source_code
client_calls = get_client_calls_for_app(source_code)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\analyzer.py", line 76, in get_client_calls_for_app
binder = t.bind_types()
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\analyzer.py", line 350, in bind_types
self.visit(self._current_ast_namespace)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\analyzer.py", line 658, in visit
return ast.NodeVisitor.visit(self, node)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\ast.py", line 253, in visit
return visitor(node)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\ast.py", line 261, in generic_visit
self.visit(item)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\analyzer.py", line 658, in visit
return ast.NodeVisitor.visit(self, node)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\ast.py", line 253, in visit
return visitor(node)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\ast.py", line 263, in generic_visit
self.visit(value)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\analyzer.py", line 658, in visit
return ast.NodeVisitor.visit(self, node)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\ast.py", line 253, in visit
return visitor(node)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\analyzer.py", line 475, in visit_Call
self._infer_function_call(node)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\analyzer.py", line 504, in _infer_function_call
child_infer.bind_types()
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\analyzer.py", line 350, in bind_types
self.visit(self._current_ast_namespace)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\analyzer.py", line 658, in visit
return ast.NodeVisitor.visit(self, node)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\ast.py", line 253, in visit
return visitor(node)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\analyzer.py", line 537, in visit_FunctionDef
self.visit(child)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\analyzer.py", line 658, in visit
return ast.NodeVisitor.visit(self, node)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\ast.py", line 253, in visit
return visitor(node)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\analyzer.py", line 408, in visit_Assign
self.generic_visit(node)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\ast.py", line 261, in generic_visit
self.visit(item)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\analyzer.py", line 658, in visit
return ast.NodeVisitor.visit(self, node)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\ast.py", line 253, in visit
return visitor(node)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\analyzer.py", line 399, in visit_Name
self._symbol_table.get_inferred_type(node.id)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\site-packages\chalice\analyzer.py", line 251, in get_inferred_type
symbol = self._local_table.lookup(name)
File "c:\users\dbatten\appdata\local\programs\python\python36\lib\symtable.py", line 95, in lookup
flags = self._table.symbols[name]
KeyError: 'stuff'
~
Issue was apparently that functions for both endpoints had the same name. Didn't realize this wasn't acceptable, though it should have been obvious.
I'd recommend a more sane error message when this occurs...
What version of chalice are you using? I believe that the error reporting logic was updated to include more information other than just the str() of the exception.
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.
@stealthycoin same issue!
I'm using chalice 1.6.0 with typing 3.6.4
Also literally same problem!
same stack trace, and chalice version, python3.6 . Now i receive the same error when I seem to be using some protected word "top" as my route method.
@app.route('/top_thing', methods=['GET'])
def top():
# do stuff
This was a weird error report for an already weird error
Same issue!!!
In my case .chalice/config.json was not well formatted.
Had the same issue, fixed once after defining different function names for second endpoint. such as def index, def index2
@app.route('/auto_thing', methods=['POST'], cors=True)
def index():
#Stuff happens in here
@app.route('/full_thing', methods=['POST'], cors=True)
def index2():
stuff = 123
Most helpful comment
Issue was apparently that functions for both endpoints had the same name. Didn't realize this wasn't acceptable, though it should have been obvious.
I'd recommend a more sane error message when this occurs...