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

Fix TypeError due to Bool arguments in ElementTree #30

Merged
merged 1 commit into from
Aug 4, 2020

Conversation

shaansubbaiah
Copy link
Member

Caused due to presence of Boolean arguments (False) while writing to
game.xml.

If speak is not set, it defaults to False in set_speak()
in card.py. The fix changes False to an empty String while writing
to game.xml.

Traceback:

1594050507.412289 ERROR root: Error saving activity object to datastore
Traceback (most recent call last):
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 1076, in _escape_attrib
    if "&" in text:
TypeError: argument of type 'bool' is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/sugar3/activity/activity.py", line 1277, in _prepare_close
    self.save()
  File "/usr/lib/python3/dist-packages/sugar3/activity/activity.py", line 978, in save
    self.write_file(file_path)
  File "/usr/share/sugar/activities/Memorize.activity/activity.py", line 409, in write_file
    self.game.model.write()
  File "/usr/share/sugar/activities/Memorize.activity/model.py", line 357, in write
    xml_file.write(tostring(root))
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 1133, in tostring
    ElementTree(element).write(stream, encoding,
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 772, in write
    serialize(write, self._root, qnames, namespaces,
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 937, in _serialize_xml
    _serialize_xml(write, e, qnames, None,
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 930, in _serialize_xml
    v = _escape_attrib(v)
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 1099, in _escape_attrib
    _raise_serialization_error(text)
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 1053, in _raise_serialization_error
    raise TypeError(
TypeError: cannot serialize False (type bool)

Fixes #29

@shaansubbaiah
Copy link
Member Author

@quozl @chimosky kindly review

@chimosky
Copy link
Member

chimosky commented Aug 1, 2020

Reviewed, thanks.

Your commit message said

If `speak` is not set, it defaults to `False` in set_speak()
in `card.py`. The fix changes `False` to an empty String while writing
to `game.xml`.

set_speak is defined in createcardpanel.py while in card.py the method that fulfils your observation is get_speak.

@shaansubbaiah
Copy link
Member Author

Thankyou for pointing that out, I have updated the commit message.

@quozl
Copy link
Contributor

quozl commented Aug 3, 2020

Commit message does not indicate how to reproduce the traceback.

Caused due to presence of Boolean arguments (False) while writing to
`game.xml`.

If `speak` is not set, it defaults to `False` in get_speak()
in `card.py`. The fix changes `False` to an empty String while writing
to `game.xml`.

Reproduce:
Click 'Edit Game' -> Make changes eg.Toggle between grouped and matched tiles
-> Click 'Play Game'

Traceback:
```
1594050507.412289 ERROR root: Error saving activity object to datastore
Traceback (most recent call last):
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 1076, in _escape_attrib
    if "&" in text:
TypeError: argument of type 'bool' is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/sugar3/activity/activity.py", line 1277, in _prepare_close
    self.save()
  File "/usr/lib/python3/dist-packages/sugar3/activity/activity.py", line 978, in save
    self.write_file(file_path)
  File "/usr/share/sugar/activities/Memorize.activity/activity.py", line 409, in write_file
    self.game.model.write()
  File "/usr/share/sugar/activities/Memorize.activity/model.py", line 357, in write
    xml_file.write(tostring(root))
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 1133, in tostring
    ElementTree(element).write(stream, encoding,
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 772, in write
    serialize(write, self._root, qnames, namespaces,
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 937, in _serialize_xml
    _serialize_xml(write, e, qnames, None,
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 930, in _serialize_xml
    v = _escape_attrib(v)
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 1099, in _escape_attrib
    _raise_serialization_error(text)
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 1053, in _raise_serialization_error
    raise TypeError(
TypeError: cannot serialize False (type bool)
```

Fixes sugarlabs#29
@shaansubbaiah
Copy link
Member Author

I have added instructions to reproduce the issue.

@quozl quozl merged commit 0520ed4 into sugarlabs:master Aug 4, 2020
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

Successfully merging this pull request may close these issues.

Editing the game doesn't work, activity gets stuck
3 participants