-
Notifications
You must be signed in to change notification settings - Fork 81
Description
Describe the bug
Hi,
Related to this discussion here - I'm trying to set my GSI properties only if the value is present. I'm attempting to use the condition parameter, but I'm running into Invalid Index Composite Attributes Provided.
I'd expect the check to ensure both index properties are provided, to run after the index's condition, not before.
For example, I want to use a truncated timestamp as a partition key that is conditionally set (next_reprocess_timestamp: 2025-12-26T00:00:000Z), and my sort key is some unique identifier (process_id: uuid). If I create an entity with my property as undefined, but I check for that undefined in my condition function, I shouldn't receive an error.
ElectroDB Version
3.4.6
ElectroDB Playground Link
ElectroDB playground link
Entity/Service Definitions
{
model: {
entity: "process",
version: "1",
service: "processapp"
},
attributes: {
process_id: {
type: "string",
required: true
},
organization: {
type: "string",
required: true
},
next_reprocess_timestamp: { // 2025-12-26T12:00:00.000Z
type: "string",
required: false
},
process_status: {
type: ["QUEUED", "COMPLETED"] as const,
required: false,
default: () => "QUEUED"
}
},
indexes: {
processes: {
pk: {
field: "pk",
composite: ["organization"]
},
sk: {
field: "sk",
composite: ["process_id"]
}
},
next: {
index: "gsi1pk-gsi1sk-index",
// this should disallow any attempts at writing to the index with no value
condition: (attr) => !!attr.next_reprocess_timestamp && attr.process_status !== "COMPLETED",
pk: {
field: "gsi1pk",
composite: ["next_reprocess_timestamp"]
},
sk: {
field: "gsi1sk",
composite: ["process_id"]
}
}
}
}
Expected behavior
If my condition evaluates to false, I'd expect both gsi1pk and gsi1sk to be unset, and no errors to be thrown.
If my condition evaluates to true, I would expect the validation to run and ensure both properties are present.