weaviate / weaviate/java-client

v6: ShardReplica.shardName has no @SerializedName, so the shard is always null

Open Beginner friendly
#621 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
34
Forks
30
PR merge metrics
No merged PRs in 30d

Description

Summary

ShardReplica carries no @SerializedName at all, so Gson looks for the field's own name, shardName. The server sends shard. The component is therefore null on every server version — the shard in a sharding-state response can never be identified.

Where it comes from

io/weaviate/client6/v1/api/cluster/ShardReplica.java (6.3.1) — the whole file:

public record ShardReplica(String shardName, List<String> replicas) {
}

JSON installs a field-naming strategy rather than relying on Gson's default:

// internal/json/JSON.java:74
gsonBuilder.setFieldNamingStrategy(PropertyFieldNamingStrategy.INSTANCE);

and that strategy only honours the ORM @Property annotation, falling back to the field name:

// internal/orm/PojoDescriptor.java:92
static String propertyName(Field field) {
  var annotation = field.getAnnotation(...annotations.Property.class);
  var propertyName = field.getName();
  if (annotation != null) { propertyName = annotation.value(); }
  return propertyName;
}

ShardReplica has neither annotation, so the expected key is literally shardName. The server's model, entities/models/replication_shard_replicas.go:

Replicas []string `json:"replicas"`
Shard    string   `json:"shard,omitempty"`

replicas matches by coincidence — the field name and the wire name happen to agree. shard does not.

Empirical confirmation

Deserializing the server's own shape through the client's JSON:

expected:<...rdReplica[shardName=[s1], replicas=[node1, n...>
 but was:<...rdReplica[shardName=[null], replicas=[node1, n...>

and the write side spells the key the server does not read:

expected:<...s","shards":[{"shard[]":"s1","replicas":["...>
 but was:<...s","shards":[{"shard[Name]":"s1","replicas":["...>

Reached through client.cluster.shardingState(...)GET /replication/sharding-stateListShardsResponseShardingState.shards().

It goes unnoticed because ClusterITest#test_shardingState only asserts that two shard lists differ; nothing reads the name.

Suggested fix

Annotate the components explicitly, as the sibling records in this package already do:

public record ShardReplica(
    @SerializedName("shard") String shardName,
    @SerializedName("replicas") List<String> replicas) {
}

Keeping the Java component named shardName avoids a breaking rename; @SerializedName is enough to bridge it. Annotating replicas too is not strictly needed today, but it stops the record depending on the field name and the wire name coinciding.

No alternate: nothing was ever stored or sent as shardName.

Version

  • java-client 6.3.1 (present since ShardReplica was introduced)
  • Weaviate 1.39.0

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open io/weaviate/client6/v1/api/cluster/ShardReplica.java and compare its record annotations with sibling records in the same package. Trace JSON handling through internal/json/JSON.java and internal/orm/PojoDescriptor.java, then run ClusterITest#test_shardingState. Done means sharding-state data preserves the server's shard name and uses the expected wire key without renaming the Java component.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
90/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.