From ca09addfb0a0228c87a37e08e0287b3bc693378c Mon Sep 17 00:00:00 2001 From: Alex Petenchea Date: Thu, 20 Mar 2025 14:56:47 +0530 Subject: [PATCH 1/6] Adding missing truncate parameters --- arango/collection.py | 18 ++++++++++++++++-- tests/test_collection.py | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/arango/collection.py b/arango/collection.py index e2dfcd2a..4e7d07a4 100644 --- a/arango/collection.py +++ b/arango/collection.py @@ -566,15 +566,29 @@ def response_handler(resp: Response) -> bool: return self._execute(request, response_handler) - def truncate(self) -> Result[bool]: + def truncate( + self, + sync: Optional[bool] = None, + compact: Optional[bool] = None, + ) -> Result[bool]: """Delete all documents in the collection. + :param sync: Block until deletion operation is synchronized to disk. + :param compact: Whether to compact the collection after truncation. :return: True if collection was truncated successfully. :rtype: bool :raise arango.exceptions.CollectionTruncateError: If operation fails. """ + params: Json = {} + if sync is not None: + params["waitForSync"] = sync + if compact is not None: + params["compact"] = compact + request = Request( - method="put", endpoint=f"/_api/collection/{self.name}/truncate" + method="put", + endpoint=f"/_api/collection/{self.name}/truncate", + params=params, ) def response_handler(resp: Response) -> bool: diff --git a/tests/test_collection.py b/tests/test_collection.py index 7ab72800..c11a6541 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -136,6 +136,8 @@ def test_collection_misc_methods(col, bad_col, cluster): # Test truncate collection assert col.truncate() is True assert len(col) == 0 + assert col.truncate(sync=True, compact=False) is True + assert len(col) == 0 # Test truncate with bad collection with assert_raises(CollectionTruncateError) as err: From d5ae65d5c6876a969d9c5813ad3fca26584cc815 Mon Sep 17 00:00:00 2001 From: Alex Petenchea Date: Thu, 20 Mar 2025 14:57:17 +0530 Subject: [PATCH 2/6] Removing unused parameter --- arango/collection.py | 1 - 1 file changed, 1 deletion(-) diff --git a/arango/collection.py b/arango/collection.py index 4e7d07a4..501da38b 100644 --- a/arango/collection.py +++ b/arango/collection.py @@ -2771,7 +2771,6 @@ def update( "returnNew": return_new, "returnOld": return_old, "ignoreRevs": not check_rev, - "overwrite": not check_rev, "silent": silent, } if sync is not None: From f27348d857899b84dad60d19d520737df505d7e2 Mon Sep 17 00:00:00 2001 From: Alex Petenchea Date: Fri, 21 Mar 2025 14:17:47 +0530 Subject: [PATCH 3/6] Minor adjustments --- arango/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arango/utils.py b/arango/utils.py index 89a0eca5..822bc736 100644 --- a/arango/utils.py +++ b/arango/utils.py @@ -64,11 +64,11 @@ def get_doc_id(doc: Union[str, Json]) -> str: def is_none_or_int(obj: Any) -> bool: - """Check if obj is None or an integer. + """Check if obj is None or a positive integer. :param obj: Object to check. :type obj: Any - :return: True if object is None or an integer. + :return: True if object is None or a positive integer. :rtype: bool """ return obj is None or (isinstance(obj, int) and obj >= 0) @@ -128,11 +128,11 @@ def build_filter_conditions(filters: Json) -> str: return "FILTER " + " AND ".join(conditions) -def validate_sort_parameters(sort: Sequence[Json]) -> bool: +def validate_sort_parameters(sort: Jsons) -> bool: """Validate sort parameters for an AQL query. :param sort: Document sort parameters. - :type sort: Sequence[Json] + :type sort: Jsons :return: Validation success. :rtype: bool :raise arango.exceptions.SortValidationError: If sort parameters are invalid. From 5bdc7a51c61b368bbc018f9064415469d91704c0 Mon Sep 17 00:00:00 2001 From: Alex Petenchea Date: Tue, 25 Mar 2025 14:19:55 +0530 Subject: [PATCH 4/6] Removing note that is no longer relevant. --- arango/collection.py | 64 -------------------------------------------- 1 file changed, 64 deletions(-) diff --git a/arango/collection.py b/arango/collection.py index 501da38b..18a417c6 100644 --- a/arango/collection.py +++ b/arango/collection.py @@ -1761,14 +1761,6 @@ def insert_many( successfully (returns document metadata) and which were not (returns exception object). - .. note:: - - In edge/vertex collections, this method does NOT provide the - transactional guarantees and validations that single insert - operation does for graphs. If these properties are required, see - :func:`arango.database.StandardDatabase.begin_batch_execution` - for an alternative approach. - :param documents: List of new documents to insert. If they contain the "_key" or "_id" fields, the values are used as the keys of the new documents (auto-generated otherwise). Any "_rev" field is ignored. @@ -1890,14 +1882,6 @@ def update_many( (returns exception object). Alternatively, you can rely on setting **raise_on_document_error** to True (defaults to False). - .. note:: - - In edge/vertex collections, this method does NOT provide the - transactional guarantees and validations that single update - operation does for graphs. If these properties are required, see - :func:`arango.database.StandardDatabase.begin_batch_execution` - for an alternative approach. - :param documents: Partial or full documents with the updated values. They must contain the "_id" or "_key" fields. :type documents: [dict] @@ -2009,14 +1993,6 @@ def update_match( ) -> Result[int]: """Update matching documents. - .. note:: - - In edge/vertex collections, this method does NOT provide the - transactional guarantees and validations that single update - operation does for graphs. If these properties are required, see - :func:`arango.database.StandardDatabase.begin_batch_execution` - for an alternative approach. - :param filters: Document filters. :type filters: dict :param body: Full or partial document body with the updates. @@ -2099,14 +2075,6 @@ def replace_many( successfully (returns document metadata) and which were not (returns exception object). - .. note:: - - In edge/vertex collections, this method does NOT provide the - transactional guarantees and validations that single replace - operation does for graphs. If these properties are required, see - :func:`arango.database.StandardDatabase.begin_batch_execution` - for an alternative approach. - :param documents: New documents to replace the old ones with. They must contain the "_id" or "_key" fields. Edge documents must also have "_from" and "_to" fields. @@ -2201,14 +2169,6 @@ def replace_match( ) -> Result[int]: """Replace matching documents. - .. note:: - - In edge/vertex collections, this method does NOT provide the - transactional guarantees and validations that single replace - operation does for graphs. If these properties are required, see - :func:`arango.database.StandardDatabase.begin_batch_execution` - for an alternative approach. - :param filters: Document filters. :type filters: dict :param body: New document body. @@ -2277,14 +2237,6 @@ def delete_many( successfully (returns document metadata) and which were not (returns exception object). - .. note:: - - In edge/vertex collections, this method does NOT provide the - transactional guarantees and validations that single delete - operation does for graphs. If these properties are required, see - :func:`arango.database.StandardDatabase.begin_batch_execution` - for an alternative approach. - :param documents: Document IDs, keys or bodies. Document bodies must contain the "_id" or "_key" fields. :type documents: [str | dict] @@ -2368,14 +2320,6 @@ def delete_match( ) -> Result[int]: """Delete matching documents. - .. note:: - - In edge/vertex collections, this method does NOT provide the - transactional guarantees and validations that single delete - operation does for graphs. If these properties are required, see - :func:`arango.database.StandardDatabase.begin_batch_execution` - for an alternative approach. - :param filters: Document filters. :type filters: dict :param limit: Max number of documents to delete. If the limit is lower @@ -2442,14 +2386,6 @@ def import_bulk( This method is faster than :func:`arango.collection.Collection.insert_many` but does not return as many details. - .. note:: - - In edge/vertex collections, this method does NOT provide the - transactional guarantees and validations that single insert - operation does for graphs. If these properties are required, see - :func:`arango.database.StandardDatabase.begin_batch_execution` - for an alternative approach. - :param documents: List of new documents to insert. If they contain the "_key" or "_id" fields, the values are used as the keys of the new documents (auto-generated otherwise). Any "_rev" field is ignored. From c5b0a2a8ae19b6007a32be2fd561c32ba02007a7 Mon Sep 17 00:00:00 2001 From: Alex Petenchea Date: Fri, 28 Mar 2025 10:27:41 +0530 Subject: [PATCH 5/6] Update arango/collection.py Co-authored-by: Anthony Mahanna <43019056+aMahanna@users.noreply.github.com> --- arango/collection.py | 1 + 1 file changed, 1 insertion(+) diff --git a/arango/collection.py b/arango/collection.py index 18a417c6..6344b2f2 100644 --- a/arango/collection.py +++ b/arango/collection.py @@ -574,6 +574,7 @@ def truncate( """Delete all documents in the collection. :param sync: Block until deletion operation is synchronized to disk. + :type sync: bool | None :param compact: Whether to compact the collection after truncation. :return: True if collection was truncated successfully. :rtype: bool From 8c3fc80c28f27204cdcc5d1fd9e24f75947206a2 Mon Sep 17 00:00:00 2001 From: Alex Petenchea Date: Fri, 28 Mar 2025 10:28:02 +0530 Subject: [PATCH 6/6] Update arango/collection.py Co-authored-by: Anthony Mahanna <43019056+aMahanna@users.noreply.github.com> --- arango/collection.py | 1 + 1 file changed, 1 insertion(+) diff --git a/arango/collection.py b/arango/collection.py index 6344b2f2..7f79fb3f 100644 --- a/arango/collection.py +++ b/arango/collection.py @@ -576,6 +576,7 @@ def truncate( :param sync: Block until deletion operation is synchronized to disk. :type sync: bool | None :param compact: Whether to compact the collection after truncation. + :type compact: bool | None :return: True if collection was truncated successfully. :rtype: bool :raise arango.exceptions.CollectionTruncateError: If operation fails.