TableSchema.converterForAttribute() returns wrong generic type
Personne n'a encore pris cette issue.
- Langage dominant
- Java
- Étoiles
- 2.6k
- Forks
- 1k
- Merge moyen
- 2 j 9 h
- PR mergées (30 j)
- 51
Description
Describe the bug
The TableSchema<T> interface has a method, converterForAttribute(Object key), which returns an AttributeConverter<T>. This AttributeConverter is meant to convert the attribute behind the given key. Unfortunately, the generic type here (T) is the type for the table record, not for the attribute.
If I have the following DynamoDbBean (non-compilable, just for explanation purposes):
@DynamoDbBean
public class ShoppingCartItem{
public static final String CUSTOMER_ID_SECONDARY_INDEX_NAME = "shopping_cart_item_by_customer_id";
private UUID customerId;
@DynamoDbSecondaryPartitionKey(indexNames = CUSTOMER_ID_SECONDARY_INDEX_NAME)
public UUID getCustomerId() {
return customerId;
}
}
If then create a corresponding DynamoDbTable<ShoppingCartItem> and try fetching the converter for the secondary partition key:
DynamoDbTable<ShoppingCartItem> table = ...;
String partitionKey = table.tableSchema().tableMetadata().indexPartitionKey(ShoppingCartItem.CUSTOMER_ID_SECONDARY_INDEX_NAME);
AttributeConverter<ShoppingCartItem> converter = table.tableSchema().converterForAttribute(partitionKey);
The AttributeConverter returned is of type AttributeConverter<ShoppingCartItem> instead of type AttributeConverter<UUID>. This makes it impossible to use the TableSchema to fetch the corresponding AttributeConverter, because it will always return an AttributeConverter scoped to the type of the table, not of the attribute.
Expected Behavior
TableSchema.converterForAttribute(Object key) should return a generic type other than AttributeConverter<T> so callers can use it properly.
Current Behavior
Described above.
Reproduction Steps
Described above.
Possible Solution
Change the return type of TableSchema.converterForAttribute(Object key).
Additional Information/Context
No response
AWS Java SDK version used
dynamodb-enhanced-2.20.56
JDK version used
1.8
Operating System and version
macOS 13.3.1
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez au point d’entrée TableSchema.converterForAttribute(Object key) et suivez sa déclaration, ses implémentations et ses appelants dans le module enhanced DynamoDB. Vérifiez le contrat générique avec l’exemple ShoppingCartItem : une clé de partition secondaire prise en charge par UUID devrait fournir un AttributeConverter sans affecter les autres utilisateurs de TableSchema.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- aws, java
- Domaine
- backend-api-design, databases
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 30/100