Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions python/perspective/perspective/manager/manager_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def __process(self, msg, post_callback, client_id=None):
# Log errors and return them to the client
error_string = str(error)
error_message = self._make_error_message(msg["id"], error_string)
logging.error("[PerspectiveManager._process] %s", error_string)
logging.exception("[PerspectiveManager._process] %s", error_string)
post_callback(self._message_to_json(msg["id"], error_message))

def _process_method_call(self, msg, post_callback, client_id):
Expand All @@ -176,6 +176,9 @@ def _process_method_call(self, msg, post_callback, client_id):
"""
if msg["cmd"] == "table_method":
table_or_view = self._tables.get(msg["name"], None)
if table_or_view is None:
error_message = self._make_error_message(msg["id"], f'Unknown table {msg["name"]}')
post_callback(self._message_to_json(msg["id"], error_message))
else:
table_or_view = self._views.get(msg["name"], None)
if table_or_view is None:
Expand Down Expand Up @@ -218,24 +221,28 @@ def _process_method_call(self, msg, post_callback, client_id):
# over the wire API.
raise PerspectiveError("table.delete() cannot be called on a remote table, as the remote has full ownership.")

table_or_view_inst = getattr(table_or_view, msg["method"], None)
if table_or_view_inst is None:
raise PerspectiveError(f'Table or view is undefined, cannot get attribute {msg["method"]}. Ensure that perspective client/server have compatible versions')

# Dispatch the method using the expected argument form
if msg["method"].startswith("to_"):
# to_format takes dictionary of options
result = getattr(table_or_view, msg["method"])(**arguments)
result = table_or_view_inst(**arguments)
elif msg["method"] in ("update", "remove"):
# Apply first arg as positional, then options dict as kwargs
data = arguments[0]
options = {}
if len(arguments) > 1 and isinstance(arguments[1], dict):
options = arguments[1]
result = getattr(table_or_view, msg["method"])(data, **options)
result = table_or_view_inst(data, **options)
elif msg["cmd"] == "table_method" and msg["method"] == "validate_expressions":
# validate_expressions on the table takes `as_string` in
# wargs,
result = getattr(table_or_view, msg["method"])(*msg.get("args", []), **arguments)
result = table_or_view_inst(*msg.get("args", []), **arguments)
else:
# otherwise parse arguments as list
result = getattr(table_or_view, msg["method"])(*arguments)
result = table_or_view_inst(*arguments)

# result has been returned from Perspective, now deliver
# it back to the user.
Expand All @@ -252,7 +259,7 @@ def _process_method_call(self, msg, post_callback, client_id):
except Exception as error:
error_string = str(error)
message = self._make_error_message(msg["id"], error_string)
logging.error("[PerspectiveManager._process_method_call] %s", error_string)
logging.exception("[PerspectiveManager._process_method_call] %s", error_string)
post_callback(self._message_to_json(msg["id"], message))

def _process_subscribe(self, msg, table_or_view, post_callback, client_id):
Expand Down