Skip to content

import plotly fails with KeyError: 'metaKeys' #612

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

Closed
chriddyp opened this issue Nov 21, 2016 · 10 comments
Closed

import plotly fails with KeyError: 'metaKeys' #612

chriddyp opened this issue Nov 21, 2016 · 10 comments
Labels
bug something broken

Comments

@chriddyp
Copy link
Member

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.

@chriddyp
Copy link
Member Author

heads up @theengineear and @Kully

@chriddyp chriddyp added the bug something broken label Nov 21, 2016
@Kully
Copy link
Contributor

Kully commented Nov 21, 2016

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

@fchevitarese
Copy link

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.

@chriddyp
Copy link
Member Author

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

@chriddyp chriddyp changed the title If downloading plot-schema fails then other parts of the code can fail unexpectedly import plotly fails with KeyError: 'metaKeys' Nov 21, 2016
@chriddyp
Copy link
Member Author

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

@chriddyp
Copy link
Member Author

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

@jlmcgehee21
Copy link

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.

@etpinard
Copy link
Contributor

import plotly relies on outside api calls.

I agree 👍

@chriddyp
Copy link
Member Author

@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.

@chriddyp
Copy link
Member Author

I am closing this issue for now and will recreate an issue with those two items (#613)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

No branches or pull requests

5 participants