Plotly.py: `import plotly` fails with `KeyError: 'metaKeys'`

Created on 21 Nov 2016  路  10Comments  路  Source: plotly/plotly.py

Right now, import plotly fails.

In [1]: import plotly
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-1-c27a4132ad2e> in <module>()
----> 1 import plotly

/Users/chriddyp/Repos/venvpy27/lib/python2.7/site-packages/plotly/__init__.py in <module>()
     29 from __future__ import absolute_import
     30
---> 31 from plotly import (plotly, graph_objs, grid_objs, tools, utils, session,
     32                     offline)
     33 from plotly.version import __version__

/Users/chriddyp/Repos/venvpy27/lib/python2.7/site-packages/plotly/plotly/__init__.py in <module>()
      8
      9 """
---> 10 from . plotly import (
     11     sign_in,
     12     update_plot_options,

/Users/chriddyp/Repos/venvpy27/lib/python2.7/site-packages/plotly/plotly/plotly.py in <module>()
     29 from requests.auth import HTTPBasicAuth
     30
---> 31 from plotly import exceptions, tools, utils, version, files
     32 from plotly.plotly import chunked_requests
     33 from plotly.session import (sign_in, update_session_plot_options,

/Users/chriddyp/Repos/venvpy27/lib/python2.7/site-packages/plotly/tools.py in <module>()
     18 from plotly import utils
     19 from plotly import exceptions
---> 20 from plotly import graph_reference
     21 from plotly import session
     22 from plotly.files import (CONFIG_FILE, CREDENTIALS_FILE, FILE_CONTENT,

/Users/chriddyp/Repos/venvpy27/lib/python2.7/site-packages/plotly/graph_reference.py in <module>()
    521 TRACE_NAMES = list(GRAPH_REFERENCE['traces'].keys())
    522
--> 523 OBJECTS = _get_objects()
    524 _patch_objects()
    525 ARRAYS = _get_arrays()

/Users/chriddyp/Repos/venvpy27/lib/python2.7/site-packages/plotly/graph_reference.py in _get_objects()
    404     for node, path in utils.node_generator(GRAPH_REFERENCE):
    405
--> 406         if any([key in path for key in GRAPH_REFERENCE['defs']['metaKeys']]):
    407             continue  # objects don't exist under nested meta keys
    408         if node.get('role') != 'object':

KeyError: 'metaKeys'

Several pages on the API are failing intermittently right now with a 504 and so I suspect that this URL https://api.plot.ly/v2/plot-schema.json?sha1=%22%22 is failing with like a 504 behind the scenes too.

bug

Most helpful comment

Thanks for reporting @fchevitarese! We are working on a fix right now

All 10 comments

heads up @theengineear and @Kully

@chriddyp Yeah, I was just experiencing this bug when working with the documentation...

Im having a similar bug. I've added the graphic to a Django view.

It work sometimes, but most of the time i receive this error:
File "/home/deploy/datagoal-2.0.0/datagoal/billing/views.py", line 11, in
6377 import plotly.offline as opy
6378 File "/home/deploy/.virtualenvs/datagoal/local/lib/python2.7/site-packages/plotly/__init__.py", line 31, in
6379 from plotly import (plotly, graph_objs, grid_objs, tools, utils, session,
6380 File "/home/deploy/.virtualenvs/datagoal/local/lib/python2.7/site-packages/plotly/plotly/__init__.py", line 10, in
6381 from . plotly import (
6382 File "/home/deploy/.virtualenvs/datagoal/local/lib/python2.7/site-packages/plotly/plotly/plotly.py", line 31, in
6383 from plotly import exceptions, tools, utils, version, files
6384 File "/home/deploy/.virtualenvs/datagoal/local/lib/python2.7/site-packages/plotly/tools.py", line 21, in
6385 from plotly import graph_reference
6386 File "/home/deploy/.virtualenvs/datagoal/local/lib/python2.7/site-packages/plotly/graph_reference.py", line 523, in
6387 OBJECTS = _get_objects()
6388 File "/home/deploy/.virtualenvs/datagoal/local/lib/python2.7/site-packages/plotly/graph_reference.py", line 406, in _get_ objects
6389 if any([key in path for key in GRAPH_REFERENCE['defs']['metaKeys']]):
6390 KeyError: 'metaKeys'

Idk if it's the same problem, but i googled and find it here.

If you guys need any kind of information, im ok with that.

Thanks for reporting @fchevitarese! We are working on a fix right now

A fix is on the way out the door right now.

This issue has been fixed through https://github.com/plotly/plotly.js/pull/1182. import plotly should not fail now. Please re-open if you are still seeing this issue!

I'm not sure what all it would entail as far as this project's layout, but it seems undesirable to me that import plotly relies on outside api calls.

I have failing tests on any file that has import plotly, even though I am not making any plotly calls in any of my tests.

I wasn't aware that this was a possibility. Should I mock out the entire plotly package for my tests, or will this change? I'm not in a good place to contribute to any sort of big change that would fix this issue, but may be able to add something to the docs warning about this behavior if someone can point me in the right direction.

import plotly relies on outside api calls.

I agree :+1:

@jlmcgehee21 100% agreed. Here's a recap of what happened here:

  • import plotly downloads the latest plot-schema.json. The plot-schema.json contains all of the information about the available keys and chart types in plotly.graph_objs. This means that as new features are added to plotly.js, the python library automatically gets those updates.
  • Today, a typo caused plot-schmea.json to be malformed. Note that the API call technically "worked" (a 200 was returned) but the format of the plot-schema.json wasn't right. Had the API call failed, the python library would have just used the cached version.
  • The typo in plot-schema.json caused a typo while creating the graph_objs. This caused import plotly to fail.

This library has fail-safes around the actual API calls - There is a 5 second timeout and a cached version of the plot-schema.json that gets included in the library: https://github.com/plotly/plotly.py/blob/master/plotly/graph_reference.py#L91-L107

but no fail safes around creating the graph_objs based off of that plot-schema: https://github.com/plotly/plotly.py/blob/master/plotly/graph_reference.py#L517-L532.

To make sure that this never happens again, we should either:

  • Extend the try / except around the construction of graph_objs off of the downloaded plot-schema.json and use the cached version if possible.
  • Remove the auto-downloading plot-schema on import and perform more frequent (weekly) releases of the python library in sync with the plotly.js version updates.

I am closing this issue for now and will recreate an issue with those two items (https://github.com/plotly/plotly.py/issues/613)

Was this page helpful?
0 / 5 - 0 ratings