From cc4713d564cf34a00ec6fe6cdc3c504ada880c6f Mon Sep 17 00:00:00 2001 From: Duda Nogueira Date: Fri, 23 Jan 2026 11:40:27 -0300 Subject: [PATCH 1/4] make _create_from_dict more resilient accepting class or name, and "text[]" and ["text[]"] for datatype --- integration/test_collection_config.py | 126 +++++++++++++++++++ weaviate/collections/collections/executor.py | 20 +++ 2 files changed, 146 insertions(+) diff --git a/integration/test_collection_config.py b/integration/test_collection_config.py index 1ed1df103..b15a2f9ee 100644 --- a/integration/test_collection_config.py +++ b/integration/test_collection_config.py @@ -1950,3 +1950,129 @@ def test_object_ttl_update(collection_factory: CollectionFactory) -> None: ) conf = collection.config.get() assert conf.object_ttl_config is None + + +def test_create_from_dict_minimal_schema(request: SubRequest) -> None: + """Test creating a collection with a minimal schema using name or class field.""" + import json + + with weaviate.connect_to_local() as client: + # Test with "name" field + client.collections.delete("ExampleSchema") + schema_with_name = '''{ + "name": "ExampleSchema" + }''' + d = json.loads(schema_with_name) + collection = client.collections.create_from_dict(d) + + # Verify collection was created with the correct name + assert collection.name == "ExampleSchema" + config = collection.config.get() + assert config.name == "ExampleSchema" + + # Clean up + client.collections.delete("ExampleSchema") + + # Test with "class" field (standard Weaviate schema format) + client.collections.delete("ExampleSchema") + schema_with_class = '''{ + "class": "ExampleSchema" + }''' + d = json.loads(schema_with_class) + collection = client.collections.create_from_dict(d) + + # Verify collection was created with the correct name + assert collection.name == "ExampleSchema" + config = collection.config.get() + assert config.name == "ExampleSchema" + + # Clean up + client.collections.delete("ExampleSchema") + + +def test_create_from_dict_datatype_string_or_array(request: SubRequest) -> None: + """Test creating a collection with dataType as string or array.""" + import json + + with weaviate.connect_to_local() as client: + # Test with dataType as string with array notation (text[] means array of text) + client.collections.delete("ExampleSchema") + schema_string_datatype = '''{ + "class": "ExampleSchema", + "properties": [ + { + "name": "texts", + "dataType": "text[]", + "indexFilterable": true, + "indexSearchable": true, + "tokenization": "word", + "indexRangeFilters": false + } + ] + }''' + d = json.loads(schema_string_datatype) + collection = client.collections.create_from_dict(d) + + # Verify collection was created with the correct property (text[] becomes TEXT_ARRAY) + assert collection.name == "ExampleSchema" + config = collection.config.get() + assert config.name == "ExampleSchema" + assert len(config.properties) == 1 + assert config.properties[0].name == "texts" + assert config.properties[0].data_type == DataType.TEXT_ARRAY + + # Clean up + client.collections.delete("ExampleSchema") + + # Test with dataType as array (standard format) + client.collections.delete("ExampleSchema") + schema_array_datatype = '''{ + "class": "ExampleSchema", + "properties": [ + { + "name": "text", + "dataType": ["text"], + "indexFilterable": true, + "indexSearchable": true, + "tokenization": "word", + "indexRangeFilters": false + } + ] + }''' + d = json.loads(schema_array_datatype) + collection = client.collections.create_from_dict(d) + + # Verify collection was created with the correct property + assert collection.name == "ExampleSchema" + config = collection.config.get() + assert config.name == "ExampleSchema" + assert len(config.properties) == 1 + assert config.properties[0].name == "text" + assert config.properties[0].data_type == DataType.TEXT + + # Clean up + client.collections.delete("ExampleSchema") + + # Test with dataType as plain string (without []) + client.collections.delete("ExampleSchema") + schema_plain_string = '''{ + "class": "ExampleSchema", + "properties": [ + { + "name": "text", + "dataType": "text" + } + ] + }''' + d = json.loads(schema_plain_string) + collection = client.collections.create_from_dict(d) + + # Verify collection was created with the correct property + assert collection.name == "ExampleSchema" + config = collection.config.get() + assert len(config.properties) == 1 + assert config.properties[0].name == "text" + assert config.properties[0].data_type == DataType.TEXT + + # Clean up + client.collections.delete("ExampleSchema") diff --git a/weaviate/collections/collections/executor.py b/weaviate/collections/collections/executor.py index 69b2baa64..f677d0d9a 100644 --- a/weaviate/collections/collections/executor.py +++ b/weaviate/collections/collections/executor.py @@ -400,6 +400,26 @@ def _create_from_dict( self, config: dict, ) -> Union[Collection, Awaitable[CollectionAsync]]: + # Support both "name" and "class" fields for backward compatibility + # If "name" is provided without "class", use it as "class" + if "name" in config and "class" not in config: + config = config.copy() + config["class"] = config.pop("name") + + # Normalize dataType: if it's a string, convert to array + # This supports both "text" and ["text"] formats, + # as well as "text[]" -> ["text[]"] + if "properties" in config: + config = config.copy() + properties = [] + for prop in config["properties"]: + prop = prop.copy() + if "dataType" in prop and isinstance(prop["dataType"], str): + # Wrap string in array: "text" -> ["text"], "text[]" -> ["text[]"] + prop["dataType"] = [prop["dataType"]] + properties.append(prop) + config["properties"] = properties + return self.__create(config=config) def _create_from_config( From f92ba57e8b1d2540d58e34042557e177a741fbb5 Mon Sep 17 00:00:00 2001 From: Duda Nogueira Date: Fri, 23 Jan 2026 11:58:56 -0300 Subject: [PATCH 2/4] linting --- integration/test_collection_config.py | 46 ++++++++++---------- weaviate/collections/collections/executor.py | 6 +-- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/integration/test_collection_config.py b/integration/test_collection_config.py index b15a2f9ee..4a779915a 100644 --- a/integration/test_collection_config.py +++ b/integration/test_collection_config.py @@ -1959,33 +1959,33 @@ def test_create_from_dict_minimal_schema(request: SubRequest) -> None: with weaviate.connect_to_local() as client: # Test with "name" field client.collections.delete("ExampleSchema") - schema_with_name = '''{ + schema_with_name = """{ "name": "ExampleSchema" - }''' + }""" d = json.loads(schema_with_name) collection = client.collections.create_from_dict(d) - + # Verify collection was created with the correct name assert collection.name == "ExampleSchema" config = collection.config.get() assert config.name == "ExampleSchema" - + # Clean up client.collections.delete("ExampleSchema") - + # Test with "class" field (standard Weaviate schema format) client.collections.delete("ExampleSchema") - schema_with_class = '''{ + schema_with_class = """{ "class": "ExampleSchema" - }''' + }""" d = json.loads(schema_with_class) collection = client.collections.create_from_dict(d) - + # Verify collection was created with the correct name assert collection.name == "ExampleSchema" config = collection.config.get() assert config.name == "ExampleSchema" - + # Clean up client.collections.delete("ExampleSchema") @@ -1997,7 +1997,7 @@ def test_create_from_dict_datatype_string_or_array(request: SubRequest) -> None: with weaviate.connect_to_local() as client: # Test with dataType as string with array notation (text[] means array of text) client.collections.delete("ExampleSchema") - schema_string_datatype = '''{ + schema_string_datatype = """{ "class": "ExampleSchema", "properties": [ { @@ -2009,10 +2009,10 @@ def test_create_from_dict_datatype_string_or_array(request: SubRequest) -> None: "indexRangeFilters": false } ] - }''' + }""" d = json.loads(schema_string_datatype) collection = client.collections.create_from_dict(d) - + # Verify collection was created with the correct property (text[] becomes TEXT_ARRAY) assert collection.name == "ExampleSchema" config = collection.config.get() @@ -2020,13 +2020,13 @@ def test_create_from_dict_datatype_string_or_array(request: SubRequest) -> None: assert len(config.properties) == 1 assert config.properties[0].name == "texts" assert config.properties[0].data_type == DataType.TEXT_ARRAY - + # Clean up client.collections.delete("ExampleSchema") - + # Test with dataType as array (standard format) client.collections.delete("ExampleSchema") - schema_array_datatype = '''{ + schema_array_datatype = """{ "class": "ExampleSchema", "properties": [ { @@ -2038,10 +2038,10 @@ def test_create_from_dict_datatype_string_or_array(request: SubRequest) -> None: "indexRangeFilters": false } ] - }''' + }""" d = json.loads(schema_array_datatype) collection = client.collections.create_from_dict(d) - + # Verify collection was created with the correct property assert collection.name == "ExampleSchema" config = collection.config.get() @@ -2049,13 +2049,13 @@ def test_create_from_dict_datatype_string_or_array(request: SubRequest) -> None: assert len(config.properties) == 1 assert config.properties[0].name == "text" assert config.properties[0].data_type == DataType.TEXT - + # Clean up client.collections.delete("ExampleSchema") - + # Test with dataType as plain string (without []) client.collections.delete("ExampleSchema") - schema_plain_string = '''{ + schema_plain_string = """{ "class": "ExampleSchema", "properties": [ { @@ -2063,16 +2063,16 @@ def test_create_from_dict_datatype_string_or_array(request: SubRequest) -> None: "dataType": "text" } ] - }''' + }""" d = json.loads(schema_plain_string) collection = client.collections.create_from_dict(d) - + # Verify collection was created with the correct property assert collection.name == "ExampleSchema" config = collection.config.get() assert len(config.properties) == 1 assert config.properties[0].name == "text" assert config.properties[0].data_type == DataType.TEXT - + # Clean up client.collections.delete("ExampleSchema") diff --git a/weaviate/collections/collections/executor.py b/weaviate/collections/collections/executor.py index f677d0d9a..7756231b6 100644 --- a/weaviate/collections/collections/executor.py +++ b/weaviate/collections/collections/executor.py @@ -405,9 +405,9 @@ def _create_from_dict( if "name" in config and "class" not in config: config = config.copy() config["class"] = config.pop("name") - + # Normalize dataType: if it's a string, convert to array - # This supports both "text" and ["text"] formats, + # This supports both "text" and ["text"] formats, # as well as "text[]" -> ["text[]"] if "properties" in config: config = config.copy() @@ -419,7 +419,7 @@ def _create_from_dict( prop["dataType"] = [prop["dataType"]] properties.append(prop) config["properties"] = properties - + return self.__create(config=config) def _create_from_config( From b80c1e5ca79e534ae3081953ce3bb589c5991230 Mon Sep 17 00:00:00 2001 From: Duda Nogueira Date: Fri, 23 Jan 2026 12:21:47 -0300 Subject: [PATCH 3/4] make collections name unique to avoid conflicts --- integration/test_collection_config.py | 55 ++++++++++++++------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/integration/test_collection_config.py b/integration/test_collection_config.py index 4a779915a..93f9f3afd 100644 --- a/integration/test_collection_config.py +++ b/integration/test_collection_config.py @@ -1996,83 +1996,86 @@ def test_create_from_dict_datatype_string_or_array(request: SubRequest) -> None: with weaviate.connect_to_local() as client: # Test with dataType as string with array notation (text[] means array of text) - client.collections.delete("ExampleSchema") - schema_string_datatype = """{ - "class": "ExampleSchema", + collection_name_1 = _sanitize_collection_name(f"{request.node.name}_array_notation") + client.collections.delete(collection_name_1) + schema_string_datatype = f"""{{ + "class": "{collection_name_1}", "properties": [ - { + {{ "name": "texts", "dataType": "text[]", "indexFilterable": true, "indexSearchable": true, "tokenization": "word", "indexRangeFilters": false - } + }} ] - }""" + }}""" d = json.loads(schema_string_datatype) collection = client.collections.create_from_dict(d) # Verify collection was created with the correct property (text[] becomes TEXT_ARRAY) - assert collection.name == "ExampleSchema" + assert collection.name == collection_name_1 config = collection.config.get() - assert config.name == "ExampleSchema" + assert config.name == collection_name_1 assert len(config.properties) == 1 assert config.properties[0].name == "texts" assert config.properties[0].data_type == DataType.TEXT_ARRAY # Clean up - client.collections.delete("ExampleSchema") + client.collections.delete(collection_name_1) # Test with dataType as array (standard format) - client.collections.delete("ExampleSchema") - schema_array_datatype = """{ - "class": "ExampleSchema", + collection_name_2 = _sanitize_collection_name(f"{request.node.name}_standard_array") + client.collections.delete(collection_name_2) + schema_array_datatype = f"""{{ + "class": "{collection_name_2}", "properties": [ - { + {{ "name": "text", "dataType": ["text"], "indexFilterable": true, "indexSearchable": true, "tokenization": "word", "indexRangeFilters": false - } + }} ] - }""" + }}""" d = json.loads(schema_array_datatype) collection = client.collections.create_from_dict(d) # Verify collection was created with the correct property - assert collection.name == "ExampleSchema" + assert collection.name == collection_name_2 config = collection.config.get() - assert config.name == "ExampleSchema" + assert config.name == collection_name_2 assert len(config.properties) == 1 assert config.properties[0].name == "text" assert config.properties[0].data_type == DataType.TEXT # Clean up - client.collections.delete("ExampleSchema") + client.collections.delete(collection_name_2) # Test with dataType as plain string (without []) - client.collections.delete("ExampleSchema") - schema_plain_string = """{ - "class": "ExampleSchema", + collection_name_3 = _sanitize_collection_name(f"{request.node.name}_plain_string") + client.collections.delete(collection_name_3) + schema_plain_string = f"""{{ + "class": "{collection_name_3}", "properties": [ - { + {{ "name": "text", "dataType": "text" - } + }} ] - }""" + }}""" d = json.loads(schema_plain_string) collection = client.collections.create_from_dict(d) # Verify collection was created with the correct property - assert collection.name == "ExampleSchema" + assert collection.name == collection_name_3 config = collection.config.get() assert len(config.properties) == 1 assert config.properties[0].name == "text" assert config.properties[0].data_type == DataType.TEXT # Clean up - client.collections.delete("ExampleSchema") + client.collections.delete(collection_name_3) From f0f1b514a2bac05c6cacf324dbd1b11e927960fe Mon Sep 17 00:00:00 2001 From: Duda Nogueira Date: Fri, 23 Jan 2026 12:50:42 -0300 Subject: [PATCH 4/4] better collection name for testing --- integration/test_collection_config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integration/test_collection_config.py b/integration/test_collection_config.py index 93f9f3afd..5183306d5 100644 --- a/integration/test_collection_config.py +++ b/integration/test_collection_config.py @@ -1996,7 +1996,7 @@ def test_create_from_dict_datatype_string_or_array(request: SubRequest) -> None: with weaviate.connect_to_local() as client: # Test with dataType as string with array notation (text[] means array of text) - collection_name_1 = _sanitize_collection_name(f"{request.node.name}_array_notation") + collection_name_1 = "TestDatatypeArrayNotation" client.collections.delete(collection_name_1) schema_string_datatype = f"""{{ "class": "{collection_name_1}", @@ -2026,7 +2026,7 @@ def test_create_from_dict_datatype_string_or_array(request: SubRequest) -> None: client.collections.delete(collection_name_1) # Test with dataType as array (standard format) - collection_name_2 = _sanitize_collection_name(f"{request.node.name}_standard_array") + collection_name_2 = "TestDatatypeStandardArray" client.collections.delete(collection_name_2) schema_array_datatype = f"""{{ "class": "{collection_name_2}", @@ -2056,7 +2056,7 @@ def test_create_from_dict_datatype_string_or_array(request: SubRequest) -> None: client.collections.delete(collection_name_2) # Test with dataType as plain string (without []) - collection_name_3 = _sanitize_collection_name(f"{request.node.name}_plain_string") + collection_name_3 = "TestDatatypePlainString" client.collections.delete(collection_name_3) schema_plain_string = f"""{{ "class": "{collection_name_3}",