From 8fb2c209a950668176a973a0a9bcd89c4ef044be Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 23 Nov 2022 07:53:14 +0530 Subject: [PATCH] Query for existing assets and then delete --- publish.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/publish.py b/publish.py index 6245f1d88..7734c2203 100755 --- a/publish.py +++ b/publish.py @@ -285,7 +285,6 @@ class GitHub(Base): # {{{ upload_url = release['upload_url'].partition('{')[0] asset_url = f'{self.url_base}/assets/{{}}' existing_assets = self.existing_assets(release['id']) - original_existing_assets = existing_assets.copy() def delete_asset(asset_id: str) -> None: r = self.requests.delete(asset_url.format(asset_id)) @@ -318,9 +317,13 @@ class GitHub(Base): # {{{ try: asset_id = r.json()['id'] except Exception: - asset_id = original_existing_assets[fname] - self.info(f'Deleting {fname} from GitHub with id: {asset_id}') - delete_asset(asset_id) + try: + asset_id = self.existing_assets(release['id'])[fname] + except KeyError: + asset_id = 0 + if asset_id: + self.info(f'Deleting {fname} from GitHub with id: {asset_id}') + delete_asset(asset_id) time.sleep(sleep_time) if self.is_nightly: