Skip to content

Commit

Permalink
Ensure free floating connections are cleared
Browse files Browse the repository at this point in the history
after leaving ActionSelection block.

Fixes #230.
  • Loading branch information
jgosmann committed Jun 20, 2019
1 parent 5c8ca8d commit 686720f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ Release History
`#229 <https://github.com/nengo/nengo_spa/pull/229>`__)


**Fixed**

- Fixed a bug where an exception within an ``ActionSelection`` block would
lead to every subsequent ``ActionSelection`` block to raise an exception.
(`#230 <https://github.com/nengo/nengo_spa/issues/230>`__,
`#231 <https://github.com/nengo/nengo_spa/pull/231>`__)


0.6.1 (April 26, 2019)
======================

Expand Down
1 change: 1 addition & 0 deletions nengo_spa/action_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __exit__(self, exc_type, exc_value, traceback):
ActionSelection.active = None
ModuleInput.routed_mode = False
if exc_type is not None:
RoutedConnection.free_floating.clear()
return
self._build()

Expand Down
15 changes: 15 additions & 0 deletions nengo_spa/tests/test_action_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,18 @@ def test_action_selection_keys_corner_cases():
with ActionSelection() as action_sel:
spa.ifmax(0.)
assert list(action_sel.keys()) == [0]


def test_action_selection_is_side_effect_free_if_exception_is_raised():
with spa.Network() as net:
state_a = spa.State(32)
state_b = spa.State(32)
state_c = spa.State(64)

with pytest.raises(SpaTypeError):
with ActionSelection():
spa.ifmax(1, state_a >> state_b, state_a >> state_c)

with ActionSelection():
pass
# should not raise

0 comments on commit 686720f

Please sign in to comment.