@@ -281,7 +281,7 @@ def plot(figure_or_data, validate=True, **plot_options):
281
281
_set_grid_column_references (figure , grid )
282
282
payload ['figure' ] = figure
283
283
284
- file_info = _create_or_update (payload , 'plot' )
284
+ file_info = _create_or_overwrite (payload , 'plot' )
285
285
286
286
# Compute viewing URL
287
287
if sharing == 'secret' :
@@ -1081,7 +1081,7 @@ def upload(cls, grid, filename=None,
1081
1081
if parent_path != '' :
1082
1082
payload ['parent_path' ] = parent_path
1083
1083
1084
- file_info = _create_or_update (payload , 'grid' )
1084
+ file_info = _create_or_overwrite (payload , 'grid' )
1085
1085
1086
1086
cols = file_info ['cols' ]
1087
1087
fid = file_info ['fid' ]
@@ -1431,10 +1431,10 @@ def get_grid(grid_url, raw=False):
1431
1431
return Grid (parsed_content , fid )
1432
1432
1433
1433
1434
- def _create_or_update (data , filetype ):
1434
+ def _create_or_overwrite (data , filetype ):
1435
1435
"""
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
1438
1438
1439
1439
Parameters
1440
1440
----------
@@ -1466,27 +1466,22 @@ def _create_or_update(data, filetype):
1466
1466
1467
1467
matching_file = json .loads (content )
1468
1468
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' ]
1483
1470
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
1488
1482
1489
- # Check response
1483
+ # Create file
1484
+ res = api_module .create (data )
1490
1485
res .raise_for_status ()
1491
1486
1492
1487
# Get resulting file content
@@ -1576,7 +1571,7 @@ def upload(cls, dashboard, filename, sharing='public', auto_open=True):
1576
1571
'world_readable' : world_readable
1577
1572
}
1578
1573
1579
- file_info = _create_or_update (data , 'dashboard' )
1574
+ file_info = _create_or_overwrite (data , 'dashboard' )
1580
1575
1581
1576
url = file_info ['web_url' ]
1582
1577
@@ -1674,7 +1669,7 @@ def upload(cls, presentation, filename, sharing='public', auto_open=True):
1674
1669
'world_readable' : world_readable
1675
1670
}
1676
1671
1677
- file_info = _create_or_update (data , 'spectacle_presentation' )
1672
+ file_info = _create_or_overwrite (data , 'spectacle_presentation' )
1678
1673
1679
1674
url = file_info ['web_url' ]
1680
1675
0 commit comments