Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use default credentials. Add checks to avoid exceptions #1603

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion cartoframes/auth/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def user_id(self):

try:
user_me = api_key_auth_client.send(ME_SERVICE, 'get').json()
self._user_id = user_me.get('user_data', {}).get('id')
user_data = user_me.get('user_data')
if user_data:
self._user_id = user_data.get('id')

except ValueError: # When the response isn't a JSON
pass
Expand Down
5 changes: 1 addition & 4 deletions cartoframes/utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ def build_extra_metrics_data(decorated_function, *args, **kwargs):
'credentials', decorated_function, *args, **kwargs)
credentials = get_credentials(credentials)
return {'user_id': credentials.user_id} if credentials and credentials.user_id else {}

# ValueError: When the decorated function doesn't contain `credentials`, e.g. creating a map
# AttributeError: When no user is set, e.g., reading a public table
except (ValueError, AttributeError):
except Exception:
return {}


Expand Down
12 changes: 7 additions & 5 deletions cartoframes/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,15 +529,17 @@ def fn(*args, **kw):


def get_parameter_from_decorator(parameter_name, decorated_function, *args, **kwargs):
parameter = None

try:
parameter = kwargs[parameter_name]

except KeyError:
try:
parameter_arg_index = inspect.getargspec(decorated_function).args.index(parameter_name)
parameter = args[parameter_arg_index]

parameter_args = inspect.getargspec(decorated_function).args
if parameter_name in parameter_args:
parameter_arg_index = parameter_args.index(parameter_name)
parameter = args[parameter_arg_index]
except IndexError:
parameter = None
pass

return parameter