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: