Skip to content

Upsert doesn't work with attributes as indexes #530

@klunejko

Description

@klunejko

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions