Skip to content

Commit df7d46b

Browse files
committed
log missing delete objects
1 parent e4d599d commit df7d46b

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

src/sasctl/_services/service.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,36 @@
44
# Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
55
# SPDX-License-Identifier: Apache-2.0
66

7+
"""Base functionality for all services."""
8+
9+
import logging
710
import time
811

12+
from deprecated.sphinx import versionadded
13+
914
from .. import core
10-
from ..core import sasctl_command, HTTPError
15+
from ..core import HTTPError, sasctl_command
1116
from ..exceptions import JobTimeoutError
1217

1318

1419
class Service(object):
20+
"""Base class for all services. Should not be used directly."""
21+
1522
_SERVICE_ROOT = None
1623

1724
is_uuid = staticmethod(core.is_uuid)
1825
get_link = staticmethod(core.get_link)
1926
request_link = staticmethod(core.request_link)
2027

28+
log = logging.getLogger(__name__)
29+
2130
@property
2231
def _SERVICE_ROOT(self):
2332
raise NotImplementedError()
2433

2534
@classmethod
2635
def is_available(cls):
27-
"""Checks if the service is currently available.
36+
"""Check if the service is currently available.
2837
2938
Returns
3039
-------
@@ -47,6 +56,22 @@ def info(cls):
4756

4857
@classmethod
4958
def request(cls, verb, path, session=None, raw=False, **kwargs):
59+
"""Make an HTTP request with a session.
60+
61+
Parameters
62+
----------
63+
verb : str
64+
path : str
65+
session : Session, optional
66+
Defaults to `current_session()`.
67+
raw : bool
68+
Whether to return the raw `Response` object. Defaults to False.
69+
kwargs : any
70+
71+
Returns
72+
-------
73+
74+
"""
5075
session = session or core.current_session()
5176

5277
if session is None:
@@ -234,7 +259,6 @@ def update_item(cls, item):
234259
None
235260
236261
"""
237-
238262
headers = getattr(item, '_headers', None)
239263
if headers is None or headers.get('etag') is None:
240264
raise ValueError(
@@ -263,10 +287,15 @@ def delete_item(cls, item):
263287
None
264288
265289
"""
290+
item_name = str(item)
266291

267292
# Try to find the item if the id can't be found
268293
if not (isinstance(item, dict) and 'id' in item):
269294
item = get_item(cls, item)
295+
if item is None:
296+
cls.log.info("Object '%s' not found. Skipping delete."
297+
% item_name)
298+
return
270299

271300
if isinstance(item, dict) and 'id' in item:
272301
item = item['id']

0 commit comments

Comments
 (0)