How to use the pyravendb.custom_exceptions.exceptions function in pyravendb

To help you get started, we’ve selected a few pyravendb 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 ravendb / ravendb-python-client / pyravendb / store / document_store.py View on Github external
def _assert_initialize(self):
        if not self._initialize:
            raise exceptions.InvalidOperationException(
                "You cannot open a session or access the database commands before initializing the document store.\
                Did you forget calling initialize()?")
github ravendb / ravendb-python-client / pyravendb / store / session_timeseries.py View on Github external
def raise_document_already_deleted_in_session(document_id, name):
        raise exceptions.InvalidOperationException(
            f"Can't modify timeseries {name} of document {document_id}, "
            f"the document was already deleted in this session.")
github ravendb / ravendb-python-client / pyravendb / connection / requests_executor.py View on Github external
def execute(self, raven_command, should_retry=True):
        if not hasattr(raven_command, 'raven_command'):
            raise ValueError("Not a valid command")
        topology_update = self._first_topology_update
        if not self._disable_topology_updates:
            if topology_update is None or topology_update.is_alive():
                try:
                    if topology_update is None:
                        with self.lock:
                            if self._first_topology_update is None:
                                if self._last_known_urls is None:
                                    raise exceptions.InvalidOperationException(
                                        "No known topology and no previously known one, cannot proceed, likely a bug")
                                self.start_first_topology_thread(self._last_known_urls)
                            topology_update = self._first_topology_update
                    topology_update.join()
                except Exception as e:
                    log.debug(str(e))
                    with self.lock:
                        if self._first_topology_update == topology_update:
                            self._first_topology_update = None
                    raise

        if self._node_selector is None:
            raise exceptions.InvalidOperationException("A connection with the server could not be established",
                                                       "node_selector cannot be None, please check your connection "
                                                       "or supply a valid node_selector")
        chosen_node = self._node_selector.get_current_node()
github ravendb / ravendb-python-client / pyravendb / commands / raven_commands.py View on Github external
def __init__(self, index_query):
        super(QueryStreamCommand, self).__init__(method="POST", is_read_request=True, use_stream=True)
        if not index_query:
            raise ValueError("index_query cannot be None")

        if index_query.wait_for_non_stale_results:
            raise exceptions.NotSupportedException("Since stream() does not wait for indexing (by design), "
                                                   "streaming query with wait_for_non_stale_results is not supported.")

        self._index_query = index_query
github ravendb / ravendb-python-client / pyravendb / commands / raven_commands.py View on Github external
def set_response(self, response):
        if response is None:
            return None
        try:
            response = response.json()
            if "Error" in response:
                raise exceptions.ErrorResponseException(response["Error"])
        except ValueError:
            raise exceptions.ErrorResponseException(
                "Failed to load document from the database please check the connection to the server")

        return response
github ravendb / ravendb-python-client / pyravendb / d_commands / database_commands.py View on Github external
if document is None:
            document = {}
        if metadata is None:
            metadata = {}
        if not isinstance(key, str):
            raise ValueError("key must be {0}".format(type("")))
        if not isinstance(document, dict) or not isinstance(metadata, dict):
            raise ValueError("document and metadata must be dict")
        data = [{"Key": key, "Document": document, "Metadata": metadata, "AdditionalData": None,
                 "Method": "PUT", "Etag": etag}]
        if etag:
            headers = {"if-None-Match": etag}
        response = self._requests_handler.http_request_handler("bulk_docs", "POST", data=data, headers=headers).json()
        if "Error" in response:
            if "ActualEtag" in response:
                raise exceptions.FetchConcurrencyException(response["Error"])
            raise exceptions.ErrorResponseException(response["Error"][:85])
        return response
github ravendb / ravendb-python-client / pyravendb / store / document_store.py View on Github external
def wait_for_operation_complete(self, operation_id, timeout=None):
        from pyravendb.commands.raven_commands import GetOperationStateCommand
        start_time = time.time()
        try:
            get_operation_command = GetOperationStateCommand(operation_id)
            while True:
                response = self.request_executor.execute(get_operation_command)
                if "Error" in response:
                    raise ValueError(response["Error"])
                if timeout and time.time() - start_time > timeout:
                    raise exceptions.TimeoutException("The Operation did not finish before the timeout end")
                if response["Status"] == "Completed":
                    return response
                if response["Status"] == "Faulted":
                    raise exceptions.InvalidOperationException(response["Result"]["Error"])
                time.sleep(0.5)
        except ValueError as e:
            raise exceptions.InvalidOperationException(e)
github ravendb / ravendb-python-client / pyravendb / d_commands / database_commands.py View on Github external
def create_database(self, database_document):
            """
            Creates a database

            @param database_document: has to be DatabaseDocument type
            """
            if "Raven/DataDir" not in database_document.settings:
                raise exceptions.InvalidOperationException("The Raven/DataDir setting is mandatory")
            db_name = database_document.database_id.replace("Raven/Databases/", "")
            Utils.name_validation(db_name)
            path = "databases/{0}".format(Utils.quote_key(db_name))
            response = self.requests_handler.http_request_handler(path, "PUT", database_document.to_json(),
                                                                  admin=True)

            if response.status_code == 502:
                raise exceptions.ErrorResponseException(
                    "Connection failed please check your connection to {0}".format(self.requests_handler.url))
            if response.status_code != 200:
                raise exceptions.ErrorResponseException(
                    "Database with the name '{0}' already exists".format(database_document.database_id))

            return response