Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a06bd15

Browse filesBrowse files
authored
Merge pull request plotly#1625 from plotly/v4_chart_studio_overwrite
V4 chart_studio: Delete existing file before creating rather than update
2 parents 2b54b67 + daa5bfc commit a06bd15
Copy full SHA for a06bd15

File tree

2 files changed

+22
-27
lines changed
Filter options

2 files changed

+22
-27
lines changed

‎packages/python/chart-studio/chart_studio/plotly/plotly.py

Copy file name to clipboardExpand all lines: packages/python/chart-studio/chart_studio/plotly/plotly.py
+21-26Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def plot(figure_or_data, validate=True, **plot_options):
281281
_set_grid_column_references(figure, grid)
282282
payload['figure'] = figure
283283

284-
file_info = _create_or_update(payload, 'plot')
284+
file_info = _create_or_overwrite(payload, 'plot')
285285

286286
# Compute viewing URL
287287
if sharing == 'secret':
@@ -1081,7 +1081,7 @@ def upload(cls, grid, filename=None,
10811081
if parent_path != '':
10821082
payload['parent_path'] = parent_path
10831083

1084-
file_info = _create_or_update(payload, 'grid')
1084+
file_info = _create_or_overwrite(payload, 'grid')
10851085

10861086
cols = file_info['cols']
10871087
fid = file_info['fid']
@@ -1431,10 +1431,10 @@ def get_grid(grid_url, raw=False):
14311431
return Grid(parsed_content, fid)
14321432

14331433

1434-
def _create_or_update(data, filetype):
1434+
def _create_or_overwrite(data, filetype):
14351435
"""
1436-
Create or update (if file exists) and grid, plot, spectacle, or dashboard
1437-
object
1436+
Create or overwrite (if file exists) and grid, plot, spectacle,
1437+
or dashboard object
14381438
14391439
Parameters
14401440
----------
@@ -1466,27 +1466,22 @@ def _create_or_update(data, filetype):
14661466

14671467
matching_file = json.loads(content)
14681468

1469-
if matching_file['filetype'] == filetype:
1470-
fid = matching_file['fid']
1471-
res = api_module.update(fid, data)
1472-
else:
1473-
raise _plotly_utils.exceptions.PlotlyError("""
1474-
'{filename}' is already a {other_filetype} in your account.
1475-
While you can overwrite {filetype}s with the same name, you can't overwrite
1476-
files with a different type. Try deleting '{filename}' in your account or
1477-
changing the filename.""".format(
1478-
filename=filename,
1479-
filetype=filetype,
1480-
other_filetype=matching_file['filetype']
1481-
)
1482-
)
1469+
fid = matching_file['fid']
14831470

1484-
except exceptions.PlotlyRequestError:
1485-
res = api_module.create(data)
1486-
else:
1487-
res = api_module.create(data)
1471+
# Delete fid
1472+
# This requires sending file to trash and then deleting it
1473+
res = api_module.trash(fid)
1474+
res.raise_for_status()
1475+
1476+
res = api_module.permanent_delete(fid)
1477+
res.raise_for_status()
1478+
except exceptions.PlotlyRequestError as e:
1479+
# Raise on trash or permanent delete
1480+
# Pass through to try creating the file anyway
1481+
pass
14881482

1489-
# Check response
1483+
# Create file
1484+
res = api_module.create(data)
14901485
res.raise_for_status()
14911486

14921487
# Get resulting file content
@@ -1576,7 +1571,7 @@ def upload(cls, dashboard, filename, sharing='public', auto_open=True):
15761571
'world_readable': world_readable
15771572
}
15781573

1579-
file_info = _create_or_update(data, 'dashboard')
1574+
file_info = _create_or_overwrite(data, 'dashboard')
15801575

15811576
url = file_info['web_url']
15821577

@@ -1674,7 +1669,7 @@ def upload(cls, presentation, filename, sharing='public', auto_open=True):
16741669
'world_readable': world_readable
16751670
}
16761671

1677-
file_info = _create_or_update(data, 'spectacle_presentation')
1672+
file_info = _create_or_overwrite(data, 'spectacle_presentation')
16781673

16791674
url = file_info['web_url']
16801675

‎packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_stream/test_stream.py

Copy file name to clipboardExpand all lines: packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_stream/test_stream.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_initialize_stream_plot(self):
3535
auto_open=False,
3636
world_readable=True,
3737
filename='stream-test')
38-
self.assertEqual('https://plot.ly/~PythonAPI/461/', url)
38+
self.assertTrue(url.startswith('https://plot.ly/~PythonAPI/'))
3939
time.sleep(.5)
4040

4141
@attr('slow')

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.