Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions arango/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ def configure(
if sync is not None:
data["waitForSync"] = sync
if schema is not None:
if not isinstance(schema, dict) or len(schema) == 0:
raise ValueError("schema parameter must be a non-empty dict")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schema removal from collections no longer possible

Medium Severity

The validation rejecting empty dicts removes the previously documented way to clear schema validation from a collection (configure(schema={})). Since schema=None means "don't change," and schema={} now raises ValueError, there's no way for users to remove an existing schema. This is a functional regression with no alternative provided.

Additional Locations (1)

Fix in Cursor Fix in Web

data["schema"] = schema
if replication_factor is not None:
data["replicationFactor"] = replication_factor
Expand Down
3 changes: 3 additions & 0 deletions arango/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,7 @@ def create_collection(
:return: Standard collection API wrapper.
:rtype: arango.collection.StandardCollection
:raise arango.exceptions.CollectionCreateError: If create fails.
:raise ValueError: If parameters are invalid.
"""
key_options: Json = {"type": key_generator, "allowUserKeys": user_keys}
if key_generator == "autoincrement":
Expand Down Expand Up @@ -1698,6 +1699,8 @@ def create_collection(
if write_concern is not None:
data["writeConcern"] = write_concern
if schema is not None:
if not isinstance(schema, dict) or len(schema) == 0:
raise ValueError("schema parameter must be a non-empty dict")
data["schema"] = schema
if computedValues is not None:
data["computedValues"] = computedValues
Expand Down
2 changes: 1 addition & 1 deletion arango/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ def format_backup_dbserver(body: Json) -> Json:
:return: Formatted body.
:rtype: dict
"""
return {"status": body["Status"]}
return {"status": body.get("Status")}


def format_backup_transfer(body: Json) -> Json:
Expand Down
2 changes: 1 addition & 1 deletion arango/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "8.2.6"
__version__ = "8.3.0"
5 changes: 1 addition & 4 deletions docs/schema.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Schema Validation

ArangoDB supports document validation using JSON schemas. You can use this
feature by providing a schema during collection creation using the ``schema``
parameter.
parameter. It must not be an empty ``dict```.

**Example:**

Expand Down Expand Up @@ -37,6 +37,3 @@ parameter.

# Modify the schema.
employees.configure(schema=my_schema)

# Remove the schema.
employees.configure(schema={})
5 changes: 5 additions & 0 deletions tests/test_backup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

import pytest
from packaging import version

Expand Down Expand Up @@ -110,6 +112,9 @@ def test_backup_management(sys_db, bad_db, cluster, skip_tests, db_version):
result = sys_db.backup.restore(backup_id_foo)
assert isinstance(result, dict)

# Wait for restore to complete
time.sleep(10)

# Test restore backup with bad database.
with assert_raises(BackupRestoreError) as err:
bad_db.backup.restore(backup_id_foo)
Expand Down
14 changes: 11 additions & 3 deletions tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ def test_collection_misc_methods(col, bad_col, cluster):
}
]

properties = col.configure(
sync=not prev_sync, schema={}, computed_values=computed_values
)
with pytest.raises(ValueError):
# schema must not be empty
properties = col.configure(
sync=not prev_sync, schema={}, computed_values=computed_values
)

properties = col.configure(sync=not prev_sync, computed_values=computed_values)

assert properties["name"] == col.name
assert properties["system"] is False
Expand Down Expand Up @@ -202,6 +206,10 @@ def test_collection_management(db, bad_db, cluster):

col_name = generate_col_name()

with pytest.raises(ValueError):
# schema must not be empty
db.create_collection(name=col_name, schema={})

col = db.create_collection(
name=col_name,
sync=True,
Expand Down
Loading