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

Error on clusters.py when shards: null #989

Closed
jfrancoa opened this issue Apr 2, 2024 · 0 comments · Fixed by #990
Closed

Error on clusters.py when shards: null #989

jfrancoa opened this issue Apr 2, 2024 · 0 comments · Fixed by #990

Comments

@jfrancoa
Copy link
Contributor

jfrancoa commented Apr 2, 2024

Trying to execute a test case, a bug in the weaviate/collections/classes/cluster.py file was found. Weaviate, when no shards exist for a specific node returns shards: null when that node does not have any active shard, however the code expects a list, not a null value:

curl "http://127.0.0.1:8080/v1/nodes?output=verbose" | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   713  100   713    0     0  72926      0 --:--:-- --:--:-- --:--:-- 79222
{
  "nodes": [
    {
      "batchStats": {
        "queueLength": 0,
        "ratePerSecond": 0
      },
      "gitHash": "d58d616",
      "name": "weaviate-0",
      "shards": null,
      "stats": {
        "objectCount": 0,
        "shardCount": 0
      },
      "status": "HEALTHY",
      "version": "1.24.2"
    },
    {
      "batchStats": {
        "queueLength": 0,
        "ratePerSecond": 0
      },
      "gitHash": "d58d616",
      "name": "weaviate-1",
      "shards": [
        {
          "class": "Multitenant_ugw5eogq",
          "compressed": false,
          "loaded": true,
          "name": "tenant0",
          "objectCount": 0,
          "vectorIndexingStatus": "READY",
          "vectorQueueLength": 0
        }
      ],
      "stats": {
        "objectCount": 0,
        "shardCount": 1
      },
      "status": "HEALTHY",
      "version": "1.24.2"
    },
    {
      "batchStats": {
        "queueLength": 0,
        "ratePerSecond": 0
      },
      "gitHash": "d58d616",
      "name": "weaviate-2",
      "shards": null,
      "stats": {
        "objectCount": 0,
        "shardCount": 0
      },
      "status": "HEALTHY",
      "version": "1.24.2"
    }
  ]
}

When trying to obtain the verbose cluster's information, the python-client fails with:

    @pytest.mark.parametrize("number_of_tenants", [1, 100, 1000])
    def test_multitenant_creation(multitenant_class, number_of_tenants):
        collection, client = multitenant_class
        collection.tenants.create([Tenant(name=f"tenant{i}") for i in range(number_of_tenants)])
        count = 0
>       for node in client.cluster.nodes(collection.name, output="verbose"):

tests/core/multitenant_test.py:40: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.venv/lib/python3.10/site-packages/weaviate/collections/cluster.py:83: in nodes
    return _ConvertFromREST.nodes_verbose(nodes)
.venv/lib/python3.10/site-packages/weaviate/collections/classes/cluster.py:45: in nodes_verbose
    return [
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

.0 = <list_iterator object at 0x10cbd3f40>

    return [
        Node(
            git_hash=node["gitHash"],
            name=node["name"],
            shards=(
>               [
                    Shard(
                        collection=shard["class"],
                        name=shard["name"],
                        node=node["name"],
                        object_count=shard["objectCount"],
                    )
                    for shard in cast(List[ShardREST], node["shards"])
                ]
                if "shards" in node
                else []
            ),
            stats=(
                Stats(
                    object_count=node["stats"]["objectCount"],
                    shard_count=node["stats"]["shardCount"],
                )
                if "stats" in node
                else []
            ),
            status=node["status"],
            version=node["version"],
        )
        for node in nodes
    ]
E   TypeError: 'NoneType' object is not iterable

A possible solution consists on adding a condition to the if, that if node["shards"] is None to also return []:

if "shards" in node and node["shards"] is not None
else []

I will submit a fix for the issue.

jfrancoa added a commit that referenced this issue Apr 2, 2024
Currently, when no shards are present on a node, Weaviate returns
shards: null, however the python-client code expects the shards
option to include a list of shards or not appear at all if there is
no shard information for that node.

fixes: gh-989
jfrancoa added a commit that referenced this issue Apr 2, 2024
Currently, when no shards are present on a node, Weaviate returns
shards: null, however the python-client code expects the shards
option to include a list of shards or not appear at all if there is
no shard information for that node.

fixes: gh-989
jfrancoa added a commit that referenced this issue Apr 2, 2024
Currently, when no shards are present on a node, Weaviate returns
shards: null, however the python-client code expects the shards
option to include a list of shards or not appear at all if there is
no shard information for that node.

fixes: gh-989
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant