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

Fixes #314 - Delegate type coercion to openpyxl #386

Merged
merged 1 commit into from
Oct 4, 2019

Conversation

claudep
Copy link
Contributor

@claudep claudep commented Oct 3, 2019

Thanks Cristiano Lopes for the initial patch.

test_tablib.py Outdated

def test_xlsx_wrong_char(self):
"""A bad character should not crash the export"""
data.append(('string', b'\x0cf'))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hugovk That test currently fails and I'd like to know your opinion. openpyxl is refusing to store some chars in a certain range:
https://bitbucket.org/openpyxl/openpyxl/src/15df72eae2f93bedc0c0c0cc8753b9107cc82d41/openpyxl/cell/cell.py#lines-70

Should we let the error break the export, or catch it and replace the offended chars by some value (empty string, '#N/A'?) I tend to favor letting the exception crash the export (and change the test accordingly).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now it's raising IllegalCharacterError:

Traceback (most recent call last):
  File "test_tablib.py", line 798, in test_xlsx_wrong_char
    data.xlsx
  File "/home/travis/build/jazzband/tablib/tablib/formats/_xlsx.py", line 39, in export_set
    dset_sheet(dataset, ws, freeze_panes=freeze_panes)
  File "/home/travis/build/jazzband/tablib/tablib/formats/_xlsx.py", line 142, in dset_sheet
    cell.value = unicode(col, errors='ignore')
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/openpyxl/cell/cell.py", line 239, in value
    self._bind_value(value)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/openpyxl/cell/cell.py", line 215, in _bind_value
    value = self.check_string(value)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/openpyxl/cell/cell.py", line 182, in check_string
    raise IllegalCharacterError
openpyxl.utils.exceptions.IllegalCharacterError

I think that's probably the right thing to do, it will let people know what the problem is and let them react appropriately (change the character, delete it, etc.).

@cristiano2lopes, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#370 is related.

Thanks Cristiano Lopes for the initial patch.
@claudep
Copy link
Contributor Author

claudep commented Oct 4, 2019

I think I will push the patch in the current state, and we can continue discussing the illegal characters exception in #370.

@claudep claudep merged commit 5fde525 into jazzband:master Oct 4, 2019
@claudep claudep deleted the issue314 branch October 4, 2019 17:45
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.

2 participants