Skip to content

Commit

Permalink
Merge pull request #1603 from CartoDB/jarroyo/ch64739/send-user-id-wh…
Browse files Browse the repository at this point in the history
…en-a-user-creates-a-map

Use default credentials. Add checks to avoid exceptions
  • Loading branch information
Jesus89 committed Apr 1, 2020
2 parents 4ba3298 + ecd00e6 commit a2323a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
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

0 comments on commit a2323a7

Please sign in to comment.