Add payload.get_field_value() to fix KeyError from pants goal idea testprojects::

Review Request #1150 - Created Oct. 10, 2014 and submitted

Information
Eric Ayers
pants
zundel/payload-missing-attribute
659
cbcaea4...
Reviewers
pants-reviews
patricklaw

There are cases where we access a field on a payload that doesn't exist.

Rather than try to figure out when target.payload.excludes exists,
I added a method Payload.get_field_value() that directly access the
value and has the capability to return 'None' for a missing field.

./pants goal idea testprojects:: --print-exception-stacktrace
...

Exception caught:
  File "/Users/zundel/Src/pants/src/python/pants/bin/pants_exe.py", line 206, in <module>
    main()
  File "/Users/zundel/Src/pants/src/python/pants/bin/pants_exe.py", line 201, in main
    _run()
  File "/Users/zundel/Src/pants/src/python/pants/bin/pants_exe.py", line 179, in _run
    result = command.run(lock)
  File "/Users/zundel/Src/pants/src/python/pants/commands/goal_runner.py", line 322, in run
    return engine.execute(context, self.goals)
  File "/Users/zundel/Src/pants/src/python/pants/engine/engine.py", line 48, in execute
    self.attempt(context, goals)
  File "/Users/zundel/Src/pants/src/python/pants/engine/round_engine.py", line 184, in attempt
    goal_executor.attempt(explain)
  File "/Users/zundel/Src/pants/src/python/pants/engine/round_engine.py", line 42, in attempt
    task.execute()
  File "/Users/zundel/Src/pants/src/python/pants/backend/codegen/tasks/code_gen.py", line 125, in execute
    dependees_by_gentarget.get(target, [])
  File "/Users/zundel/Src/pants/src/python/pants/backend/codegen/tasks/apache_thrift_gen.py", line 183, in createtarget
    return self._create_java_target(gentarget, dependees)
  File "/Users/zundel/Src/pants/src/python/pants/backend/codegen/tasks/apache_thrift_gen.py", line 201, in _create_java_target
    return self._inject_target(target, dependees, self.gen_java, 'java', create_target)
  File "/Users/zundel/Src/pants/src/python/pants/backend/codegen/tasks/apache_thrift_gen.py", line 223, in _inject_target
    tgt = create_target(files, deps)
  File "/Users/zundel/Src/pants/src/python/pants/backend/codegen/tasks/apache_thrift_gen.py", line 200, in create_target
    excludes=target.payload.excludes)
  File "/Users/zundel/Src/pants/src/python/pants/base/payload.py", line 98, in __getattr__
    field = self._fields[attr]

Exception message: 'excludes'

Added unit test, CI is baking.

Issues

  • 0
  • 1
  • 0
  • 1
Description From Last Updated
Eric Ayers
Eric Ayers
Patrick Lawson
Eric Ayers
Review request changed

Status: Closed (submitted)

Change Summary:

commit 9087fdf
David Turner

   
src/python/pants/base/payload.py (Diff revision 2)
 
 

How does this method differ from the method immediately above it?

  1. They are subtly different in that this one returns the value of the payload field, not the payload field itself. See the unit test for an example.

Loading...