Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/#486 #488

Merged
merged 6 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
14 changes: 14 additions & 0 deletions integration/test_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional

import pytest
import requests

import weaviate
from weaviate import Tenant, TenantActivityStatus
Expand Down Expand Up @@ -120,6 +121,19 @@ def test_class_tenants(client: weaviate.Client):
assert len(tenants_get) == 1


def test_update_schema_with_no_properties(client: weaviate.Client):
single_class = {"class": "NoProperties"}

requests.post("http://localhost:8080/v1/schema", json=single_class)
assert client.schema.exists("NoProperties")

client.schema.update_config("NoProperties", {"vectorIndexConfig": {"ef": 64}})
assert client.schema.exists("NoProperties")

client.schema.delete_class("NoProperties")
assert client.schema.exists("NoProperties") is False


def test_class_tenants_activate_deactivate(client: weaviate.Client):
class_name = "MultiTenancyActivateDeactivateSchemaTest"
uncap_class_name = "multiTenancyActivateDeactivateSchemaTest"
Expand Down
7 changes: 0 additions & 7 deletions test/schema/properties/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from test.util import mock_connection_func, check_error_message, check_startswith_error_message
from weaviate.exceptions import (
UnexpectedStatusCodeException,
SchemaValidationException,
)
from weaviate.schema.properties import Property

Expand All @@ -21,18 +20,12 @@ def test_create(self):

# invalid calls
error_message = "Class name must be of type str but is "
check_property_error_message = 'Property does not contain "dataType"'
requests_error_message = "Property was created properly."

with self.assertRaises(TypeError) as error:
prop.create(35, {})
check_error_message(self, error, error_message + str(int))

# test if `check_property` is called in `create`
with self.assertRaises(SchemaValidationException) as error:
prop.create("Class", {})
check_error_message(self, error, check_property_error_message)

prop = Property(mock_connection_func("post", side_effect=RequestsConnectionError("Test!")))
with self.assertRaises(RequestsConnectionError) as error:
prop.create("Class", {"name": "test", "dataType": ["test_type"]})
Expand Down
7 changes: 0 additions & 7 deletions weaviate/schema/crud_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from weaviate.exceptions import UnexpectedStatusCodeException
from weaviate.schema.properties import Property
from weaviate.schema.validate_schema import (
validate_schema,
check_class,
CLASS_KEYS,
PROPERTY_KEYS,
)
Expand Down Expand Up @@ -176,8 +174,6 @@ def create(self, schema: Union[dict, str]) -> None:
"""

loaded_schema = _get_dict_from_object(schema)
# validate the schema before loading
validate_schema(loaded_schema)
self._create_classes_with_primitives(loaded_schema["classes"])
self._create_complex_properties_from_classes(loaded_schema["classes"])

Expand Down Expand Up @@ -230,8 +226,6 @@ def create_class(self, schema_class: Union[dict, str]) -> None:
"""

loaded_schema_class = _get_dict_from_object(schema_class)
# validate the class before loading
check_class(loaded_schema_class)
self._create_class_with_primitives(loaded_schema_class)
self._create_complex_properties_from_class(loaded_schema_class)

Expand Down Expand Up @@ -437,7 +431,6 @@ def update_config(self, class_name: str, config: dict) -> None:
class_name = _capitalize_first_letter(class_name)
class_schema = self.get(class_name)
new_class_schema = _update_nested_dict(class_schema, config)
check_class(new_class_schema)

path = "/schema/" + class_name
try:
Expand Down
4 changes: 0 additions & 4 deletions weaviate/schema/properties/crud_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from weaviate.connect import Connection
from weaviate.exceptions import UnexpectedStatusCodeException
from weaviate.schema.validate_schema import check_property
from weaviate.util import _get_dict_from_object, _capitalize_first_letter


Expand Down Expand Up @@ -66,9 +65,6 @@ def create(self, schema_class_name: str, schema_property: dict) -> None:

loaded_schema_property = _get_dict_from_object(schema_property)

# check if valid property
check_property(loaded_schema_property)

schema_class_name = _capitalize_first_letter(schema_class_name)

path = f"/schema/{schema_class_name}/properties"
Expand Down
5 changes: 3 additions & 2 deletions weaviate/schema/validate_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ def check_class(class_definition: dict) -> None:
]:
_check_key_type(key, class_definition[key], dict)
if key in ["properties"]:
_check_key_type(key, class_definition[key], list)
if (properties := class_definition[key]) is not None:
_check_key_type(key, properties, list)

if "properties" in class_definition:
if "properties" in class_definition and class_definition["properties"] is not None:
for class_property in class_definition["properties"]:
check_property(class_property)
tsmith023 marked this conversation as resolved.
Show resolved Hide resolved

Expand Down