auto-pi-lot / autopilot

Distributed behavioral experiments
https://docs.auto-pi-lot.com
Mozilla Public License 2.0
93 stars 24 forks source link

Cannot create subject #183

Open cxrodgers opened 2 years ago

cxrodgers commented 2 years ago

I am on the dev branch, so v0.5. I'm having trouble creating a subject by clicking the "+" in the Terminal GUI under the green button.

If I complete the subject's "id" textbox, but none of the other optional fields, and click "OK" I get this:

[22-08-02T16:12:38] DEBUG    [gui.widgets.subject.New_Subject_Wizard] Clicked OK to create subject                                                                  subject.py:57
Traceback (most recent call last):
  File "/home/mouse/dev/autopilot/autopilot/gui/widgets/subject.py", line 58, in _accept
    model = self.bio_tab.validate(dialog=True)
  File "/home/mouse/dev/autopilot/autopilot/gui/widgets/model.py", line 232, in validate
    kwargs = self.dict()
  File "/home/mouse/dev/autopilot/autopilot/gui/widgets/model.py", line 138, in dict
    kwargs[key] = input.value()
  File "/home/mouse/dev/autopilot/autopilot/gui/widgets/input.py", line 271, in value
    return literal_eval(self._widget.text())
  File "/home/mouse/miniconda3/envs/autopilot/lib/python3.9/ast.py", line 62, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "/home/mouse/miniconda3/envs/autopilot/lib/python3.9/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 0

SyntaxError: unexpected EOF while parsing

If I put text in all the optional fields in the bio, I get this

[22-08-02T16:13:10] DEBUG    [gui.widgets.subject.New_Subject_Wizard] Clicked OK to create subject                                                                  subject.py:57
Traceback (most recent call last):
  File "/home/mouse/dev/autopilot/autopilot/gui/widgets/subject.py", line 58, in _accept
    model = self.bio_tab.validate(dialog=True)
  File "/home/mouse/dev/autopilot/autopilot/gui/widgets/model.py", line 232, in validate
    kwargs = self.dict()
  File "/home/mouse/dev/autopilot/autopilot/gui/widgets/model.py", line 138, in dict
    kwargs[key] = input.value()
  File "/home/mouse/dev/autopilot/autopilot/gui/widgets/input.py", line 271, in value
    return literal_eval(self._widget.text())
  File "/home/mouse/miniconda3/envs/autopilot/lib/python3.9/ast.py", line 105, in literal_eval
    return _convert(node_or_string)
  File "/home/mouse/miniconda3/envs/autopilot/lib/python3.9/ast.py", line 104, in _convert
    return _convert_signed_num(node)
  File "/home/mouse/miniconda3/envs/autopilot/lib/python3.9/ast.py", line 78, in _convert_signed_num
    return _convert_num(node)
  File "/home/mouse/miniconda3/envs/autopilot/lib/python3.9/ast.py", line 69, in _convert_num
    _raise_malformed_node(node)
  File "/home/mouse/miniconda3/envs/autopilot/lib/python3.9/ast.py", line 66, in _raise_malformed_node
    raise ValueError(f'malformed node or string: {node!r}')
ValueError: malformed node or string: <ast.Name object at 0x7f1044048df0>
sneakers-the-rat commented 2 years ago

What the heck i'm also getting this, but am sure that this worked because there's a roundtrip test of getting and setting from the widget here: https://github.com/auto-pi-lot/autopilot/blob/04b5968ba02c8a1413a27eb6a138b6a186b130f1/tests/test_gui/test_widget_model.py#L41

In any case i'm going to make a more informative error message when validating (there already is one, but this happens before it: https://github.com/auto-pi-lot/autopilot/blob/04b5968ba02c8a1413a27eb6a138b6a186b130f1/autopilot/gui/widgets/model.py#L234-L243

1 second

cxrodgers commented 2 years ago

We need a test for the test! :laughing:

sneakers-the-rat commented 2 years ago

OK got it:

https://github.com/auto-pi-lot/autopilot/commit/0a2f081369b794920e62c1afee9e8cbf2e681dd6

see the diff there for specifics, but in short:

lmk if that doesn't work.

edit: i am pretty happy with the design of that model widget and the inputs, it was pretty easy and very clear how to make that fix. sigh if only I had known how to write decent code when I started autopilot lol. Oh well! fixing it up piece by piece.

cxrodgers commented 2 years ago

Works great, thanks!