-
Notifications
You must be signed in to change notification settings - Fork 385
Description
Issue summary
When running import shopify, a blocking web request is made to Shopify's API.
This means that...
- App startup is dependent on Shopify's API being online.
- Services running in production can fail to start if Shopify's API is offline (as it was briefly today).
- Startup time is slower because of the API request.
- Offline development and testing is not possible.
Expected behavior
We would expected that the cost of importing a library is roughly the cost of loading that library's files into memory.
We would also expect that libraries only make network requests when explicitly asked to, so that developers are able to handle errors gracefully, monitor network performance, mock out in tests, and generally understand the implications of the code they write.
Actual behavior
This stacktrace shows the Shopify library making an API request at import time:
File "styleme/shopify/utils.py", line 8, in <module>
import shopify
File "__init__.py", line 2, in <module>
from shopify.session import Session, ValidationException
File "/opt/venv/lib/python3.5/site-packages/shopify/session.py", line 12, in <module>
from shopify.api_version import ApiVersion, Release, Unstable
File "/opt/venv/lib/python3.5/site-packages/shopify/api_version.py", line 86, in <module>
ApiVersion.define_known_versions()
File "/opt/venv/lib/python3.5/site-packages/shopify/api_version.py", line 28, in define_known_versions
req = request.urlopen("https://app.shopify.com/services/apis.json")
File "urllib/request.py", line 163, in urlopen
return opener.open(url, data, timeout)
File "urllib/request.py", line 472, in open
response = meth(req, response)
File "urllib/request.py", line 582, in http_response
'http', request, response, code, msg, hdrs)
File "urllib/request.py", line 510, in error
return self._call_chain(*args)
File "urllib/request.py", line 444, in _call_chain
result = func(*args)
File "urllib/request.py", line 590, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
We found this because our webserver crashed on startup with an HTTP 520 error from Shopify's API.
Also note that the issue traces to the Session import, which means it's not possible to circumvent this with careful importing.
Steps to reproduce the problem
import shopify
Specifications
shopify_python_apiversion: 8.2.0pyactiveresourceversion: 2.2.2- Shopify API version used (e.g.
'2020-07'): N/A