-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d13b87c
commit 340d960
Showing
7 changed files
with
175 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import re | ||
|
||
build_regex = re.compile(r'^(?P<filename>[\w@-]+)(?P<extension>.*)$') | ||
|
||
check_regex = re.compile( | ||
r'^(?P<filename>.*)[.]v[\w-]+m[0-9a-fA-F]+(?P<extension>(?:(?:(?<![.])[.])?[\w])+)$' | ||
) | ||
|
||
|
||
def build_fingerprint(path, version, hash_value): | ||
res = build_regex.match(path) | ||
|
||
return '{}.v{}m{}{}'.format( | ||
res.group('filename'), | ||
str(version).replace('.', '_'), | ||
hash_value, | ||
res.group('extension'), | ||
) | ||
|
||
|
||
def check_fingerprint(path): | ||
# Check if the resource has a fingerprint | ||
res = check_regex.match(path) | ||
|
||
# Resolve real resource name from fingerprinted resource path | ||
return ( | ||
res.group('filename') + res.group('extension') | ||
if res is not None | ||
else path, | ||
res is not None, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
from dash.fingerprint import build_fingerprint, check_fingerprint | ||
|
||
version = 1 | ||
hash_value = 1 | ||
|
||
valid_resources = [ | ||
{'path': 'react@16.8.6.min.js', 'fingerprint': 'react@16.v1m1.8.6.min.js'}, | ||
{'path': 'react@16.8.6.min.js', 'fingerprint': 'react@16.v1_1_1m1234567890abcdef.8.6.min.js', 'version': '1.1.1', 'hash': '1234567890abcdef' }, | ||
{'path': 'react@16.8.6.min.js', 'fingerprint': 'react@16.v1_1_1-alpha_1m1234567890abcdef.8.6.min.js', 'version': '1.1.1-alpha.1', 'hash': '1234567890abcdef' }, | ||
{'path': 'dash.plotly.js', 'fingerprint': 'dash.v1m1.plotly.js'}, | ||
{'path': 'dash.plotly.j_s', 'fingerprint': 'dash.v1m1.plotly.j_s'}, | ||
{'path': 'dash.plotly.css', 'fingerprint': 'dash.v1m1.plotly.css'}, | ||
{'path': 'dash.plotly.xxx.yyy.zzz', 'fingerprint': 'dash.v1m1.plotly.xxx.yyy.zzz'} | ||
] | ||
|
||
valid_fingerprints = [ | ||
'react@16.v1_1_2m1571771240.8.6.min.js', | ||
'dash.plotly.v1_1_1m1234567890.js', | ||
'dash.plotly.v1_1_1m1234567890.j_s', | ||
'dash.plotly.v1_1_1m1234567890.css', | ||
'dash.plotly.v1_1_1m1234567890.xxx.yyy.zzz', | ||
'dash.plotly.v1_1_1-alpha1m1234567890.js', | ||
'dash.plotly.v1_1_1-alpha_3m1234567890.js', | ||
'dash.plotly.v1_1_1m1234567890123.js', | ||
'dash.plotly.v1_1_1m4bc3.js' | ||
] | ||
|
||
invalid_fingerprints = [ | ||
'dash.plotly.v1_1_1m1234567890..js', | ||
'dash.plotly.v1_1_1m1234567890.', | ||
'dash.plotly.v1_1_1m1234567890..', | ||
'dash.plotly.v1_1_1m1234567890.js.', | ||
'dash.plotly.v1_1_1m1234567890.j-s' | ||
] | ||
|
||
def test_fingerprint(): | ||
for resource in valid_resources: | ||
# The fingerprint matches expectations | ||
fingerprint = build_fingerprint(resource.get('path'), resource.get('version', version), resource.get('hash', hash_value)) | ||
assert fingerprint == resource.get('fingerprint') | ||
|
||
(original_path, has_fingerprint) = check_fingerprint(fingerprint) | ||
# The inverse operation returns that the fingerprint was valid and the original path | ||
assert has_fingerprint | ||
assert original_path == resource.get('path') | ||
|
||
for resource in valid_fingerprints: | ||
(_, has_fingerprint) = check_fingerprint(resource) | ||
assert has_fingerprint | ||
|
||
for resource in invalid_fingerprints: | ||
(_, has_fingerprint) = check_fingerprint(resource) | ||
assert not has_fingerprint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
340d960
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this commit, my dash app always return the following error:
Exception on /_dash-component-suites/dash_bootstrap_components/_components.v0_7_2m1572382057/dash_bootstrap_components.min.js [GET]
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functionsrule.endpoint
File "/usr/local/lib/python2.7/site-packages/dash/dash.py", line 700, in serve_component_suites
package_name, path_in_package_dist, self.registered_paths
DependencyException: "dash_bootstrap_components" is registered but the path requested is not valid.
The path requested: "_components.v0_7_2m1572382057/dash_bootstrap_components.min.js"
List of registered paths: defaultdict(<type 'set'>, {'dash_bootstrap_components': set(['_components/dash_bootstrap_components.min.js']), u'timelinevisualizer': set(['timelinevisualizer.min.js']), u'networkgraphvisualizer': set(['networkgraphvisualizer.min.js']), u'dash_table': set(['bundle.js', 'async
table.js', 'asyncexport.js', 'asyncexport.js.map', 'asynctable.js.map', 'bundle.js.map']), 'dash_renderer': set(['dash_renderer.min.js.map', 'react@16.8.6.min.js', 'prop-types@15.7.2.min.js', 'react-dom@16.8.6.min.js', 'dash_renderer.min.js']), 'dash_core_components': set(['asyncgraph.js.map', 'asyncgraph.js', 'dash_core_components.min.js', 'dash_core_components.min.js.map', 'highlight.pack.js', 'asyncplotlyjs.js', 'asyncplotlyjs.js.map', 'plotly-1.50.1.min.js']), 'dash_html_components': set(['dash_html_components.min.js.map', 'dash_html_components.min.js']), u'sd_material_ui': set(['sd_material_ui.min.js']), u'datatable': set(['datatable.min.js'])})172.17.0.1 - - [29/Oct/2019 20:58:31] "GET /_dash-component-suites/dash_bootstrap_components/_components.v0_7_2m1572382057/dash_bootstrap_components.min.js HTTP/1.1" 500 -
I know this has something to do with caching. Do you have any suggestions on how to fix this?
340d960
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is your app structured such that the
dash.Dash
is instantiated before all the components are imported?If so I think this will be covered by the fix we're working on right now #985 but you can fix it in the short term by explicitly importing all components right above where you instantiate the app.
340d960
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh sorry... no this is a separate issue, seems like there's a problem with how we're adding the cache string now vs. the structure of
dash_bootstrap_components
. We're investigating!340d960
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by #987 - we'll release v1.5.1 shortly including that and one more fix.
340d960
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/plotly/dash/releases/tag/v1.5.1 - @Aprilhuu can you confirm that this works now?
340d960
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your help! Everything works now.😊