altair-viz / altair_saver

Altair extension for saving charts in a variety of formats.
BSD 3-Clause "New" or "Revised" License
94 stars 32 forks source link

Saving SVG fails with Selenium InvalidArgumentException: Message: invalid argument: missing command parameters #77

Closed sacundim closed 3 years ago

sacundim commented 3 years ago

I just made some changes to my app that had nothing to do with the code that saves charts, and somehow now SVG saving is broken with the exception below. PNG saves just fine. Seriously, I didn't touch the code for saving charts; the only way I can imagine my code changes affecting these code paths are that I added a bunch of library dependencies.

I'm using:

I'm enabling altair_saver renderers here, and my call into the Altair save method is here.

Stack trace:

Traceback (most recent call last):
  File "/usr/local/bin/covid19pr", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/covid_19_puerto_rico/__init__.py", line 81, in main
    target.render(date_range)
  File "/usr/local/lib/python3.7/site-packages/covid_19_puerto_rico/charts.py", line 29, in render
    self.render_bulletin_date(df, bulletin_date)
  File "/usr/local/lib/python3.7/site-packages/covid_19_puerto_rico/charts.py", line 37, in render_bulletin_date
    self.output_formats)
  File "/usr/local/lib/python3.7/site-packages/covid_19_puerto_rico/util.py", line 42, in save_chart
    chart.save(filename)
  File "/usr/local/lib/python3.7/site-packages/altair/vegalite/v4/api.py", line 476, in save
    result = save(**kwds)
  File "/usr/local/lib/python3.7/site-packages/altair/utils/save.py", line 121, in save
    **kwargs,
  File "/usr/local/lib/python3.7/site-packages/altair/utils/mimebundle.py", line 60, in spec_to_mimebundle
    return altair_saver.render(spec, format, mode=mode, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/altair_saver/_core.py", line 257, in render
    mimebundle.update(saver.mimebundle(fmt))
  File "/usr/local/lib/python3.7/site-packages/altair_saver/savers/_saver.py", line 90, in mimebundle
    bundle[mimetype] = self._serialize(fmt, "mimebundle")
  File "/usr/local/lib/python3.7/site-packages/altair_saver/savers/_selenium.py", line 284, in _serialize
    out = self._extract(fmt)
  File "/usr/local/lib/python3.7/site-packages/altair_saver/savers/_selenium.py", line 278, in _extract
    result = driver.execute_async_script(EXTRACT_CODE, self._spec, opt, fmt)
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 659, in execute_async_script
    'args': converted_args})['value']
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: missing command parameters
sacundim commented 3 years ago

Well, turns out that PNG doesn't just save fine... it saves fine in one context but not another. I say "context" because I can't understand at all why it would be any different, it's the same code path more than once in the same process.

sacundim commented 3 years ago

Ah, I found the problem. It's not in altair_saver, it's Altair producing invalid JSON with a NaN tokens. I have filed an issue in Altair.