How to use the tabpy.tabpy_server.common.util.format_exception function in tabpy

To help you get started, we’ve selected a few tabpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tableau / TabPy / tabpy / tabpy_server / handlers / query_plane_handler.py View on Github external
def _process_query(self, endpoint_name, start):
        self.logger.log(logging.DEBUG, f"Processing query {endpoint_name}...")
        try:
            self._add_CORS_header()

            if not self.request.body:
                self.request.body = {}

            # extract request data explicitly for caching purpose
            request_json = self.request.body.decode("utf-8")

            # Sanitize input data
            data = self._sanitize_request_data(json.loads(request_json))
        except Exception as e:
            self.logger.log(logging.ERROR, str(e))
            err_msg = format_exception(e, "Invalid Input Data")
            self.error_out(400, err_msg)
            return

        try:
            (po_name, _) = self._get_actual_model(endpoint_name)

            # po_name is None if self.python_service.ps.query_objects.get(
            # endpoint_name) is None
            if not po_name:
                self.error_out(
                    404, "UnknownURI", info=f'Endpoint "{endpoint_name}" does not exist'
                )
                return

            po_obj = self.python_service.ps.query_objects.get(po_name)
github tableau / TabPy / tabpy / tabpy_server / handlers / endpoints_handler.py View on Github external
self.finish()
                return

            self.logger.log(logging.DEBUG, f'Adding endpoint "{name}"')
            err_msg = yield self._add_or_update_endpoint("add", name, 1, request_data)
            if err_msg:
                self.error_out(400, err_msg)
            else:
                self.logger.log(logging.DEBUG, f"Endpoint {name} successfully added")
                self.set_status(201)
                self.write(self.tabpy_state.get_endpoints(name))
                self.finish()
                return

        except Exception as e:
            err_msg = format_exception(e, "/add_endpoint")
            self.error_out(500, "error adding endpoint", err_msg)
            self.finish()
            return
github tableau / TabPy / tabpy / tabpy_server / handlers / endpoint_handler.py View on Github external
if endpoint_info["type"] != "alias":
                delete_path = get_query_object_path(
                    self.settings["state_file_path"], name, None
                )
                try:
                    yield self._delete_po_future(delete_path)
                except Exception as e:
                    self.error_out(400, f"Error while deleting: {e}")
                    self.finish()
                    return

            self.set_status(204)
            self.finish()

        except Exception as e:
            err_msg = format_exception(e, "delete endpoint")
            self.error_out(500, err_msg)
            self.finish()

        on_state_change(
            self.settings, self.tabpy_state, self.python_service, self.logger
        )
github tableau / TabPy / tabpy / tabpy_server / psws / python_service.py View on Github external
f"endpoint: {object_uri}"
                        ),
                    )

                logger.debug(f"Querying endpoint with params ({params})...")
                if isinstance(params, dict):
                    result = pred_obj.query(**params)
                else:
                    result = pred_obj.query(*params)

                return QuerySuccessful(object_uri, version, result)
            else:
                return UnknownURI(object_uri)
        except Exception as e:
            logger.exception(e)
            err_msg = format_exception(e, "/query")
            logger.error(err_msg)
            return QueryFailed(uri=object_uri, error=err_msg)
github tableau / TabPy / tabpy / tabpy_server / psws / callbacks.py View on Github external
)

                python_service.manage_request(msg)
                wait_for_endpoint_loaded(python_service, object_name)

                # cleanup old version of endpoint files
                if object_version > 2:
                    cleanup_endpoint_files(
                        object_name,
                        settings[SettingsParameters.UploadDir],
                        logger=logger,
                        retain_versions=[object_version, object_version - 1],
                    )

    except Exception as e:
        err_msg = format_exception(e, "on_state_change")
        logger.log(
            logging.ERROR, f"Error submitting update model request: error={err_msg}"
        )
github tableau / TabPy / tabpy / tabpy_server / handlers / query_plane_handler.py View on Github external
uid = _get_uuid()

            # record query w/ request ID in query log
            qry = Query(po_name, request_json)
            gls_time = 0
            # send a query to PythonService and return
            (gls_time, _) = self._handle_result(po_name, data, qry, uid)

            # if error occurred, GLS time is None.
            if not gls_time:
                return

        except Exception as e:
            self.logger.log(logging.ERROR, str(e))
            err_msg = format_exception(e, "process query")
            self.error_out(500, "Error processing query", info=err_msg)
            return