electrodb icon indicating copy to clipboard operation
electrodb copied to clipboard

Upsert doesn't work with attributes as indexes

Open klunejko opened this issue 3 months ago • 1 comments

Describe the bug Using upsert on an entity with attributes as index results in a UpdateExpression that tries to update the key, which then fails. I can work around it using update().set(), but I then have to first delete the index attribute from the upsert record, which typescript doesn't allow for non-optional properties. So just a bit annoying.

Oh and not directly related to this, but ignoreOwnership should apply to new records as well. Makes no sense to have an existing table that's partially populated with __edb_ fields.

ElectroDB Version (e.g. 3.4.6)

ElectroDB Playground Link https://electrodb.fun/?#code/JYWwDg9gTgLgBAbzgUQHY2DAnnAvnAMyghDgCIBTAGwoGMZiATAIzIG4AoD2iVAZ3gwAhsxpwAvOSwQArlAD6w0RXmohICuy49+8KhADmEuKgoB3FOkxYAFBzgPE9xy5ARG1AFxOXvxxStsbzJ9A3koOmhGMgAaZz8XADcKKD5gXmCARlj4hIc+FMTgWgpg0Jy83Di8oRgGYGYZGAo+bwRcvOAweSFGRig2jrzHbDBS8gEoYFQDCuG-CIBHGWAIxm8GGQpq+d8I3oB5VCosDagtnfmqob8KAA8wVZbFGCpB3d9R8bJUGRBmFJzK6XYZCMBgd4fEZYMbBSbTWYgypIhK0KjFADW8mA6x8UIcXzh9RmQOG1w+GA0AnUELx+MJE2JiJuvnJCTZfmmHjuLUh82YWAAkmAAIJ9AZ0qFgDF8-GOAjAai4shdHri0lyuA8cAQNLNbwAbRV3V6-TIAF0UcCWS4OayQXakEoxLgOABKTgcUIAOhkYAKsBsSFVpolZEyACYAOzegAMce92RicDBtLIfBIFBgAAsEWQ8G7vQYIEHcsADKhoBQDmZTKlc7TNtsOLgPRwgA

Expected behavior The index should not be included as part of the UpdateExpression.

Errors

ElectroError: Error thrown by DynamoDB client: "One or more parameter values were invalid: Cannot update attribute ip_addr. This attribute is part of the key" - For more detail on this error reference: https://electrodb.dev/en/reference/errors/#aws-error

klunejko avatar Oct 07 '25 20:10 klunejko

Actually, made a mistake, that work around doesn't work either.

If the index attribute is missing, the request fails: Incomplete or invalid key composite attributes supplied. Missing properties: "ip_addr".

If it's present, it also fails: ElectroAttributeValidationError [ElectroError]: Attribute "ip_addr" is Read-Only and cannot be updated

klunejko avatar Oct 07 '25 20:10 klunejko