Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computed attributes ignore field property during update #281

Closed
sam3d opened this issue Aug 19, 2023 · 4 comments
Closed

Computed attributes ignore field property during update #281

sam3d opened this issue Aug 19, 2023 · 4 comments

Comments

@sam3d
Copy link
Sponsor

sam3d commented Aug 19, 2023

Describe the bug
I'd expect an attribute to adhere to the field property at all times - whether or not it's a computed attribute. However, computed attributes seem to ignore the field property during an update operation when their update is triggered from another attribute being set.

ElectroDB Version
2.8.0

ElectroDB Playground Link

https://electrodb.fun/?#code/JYWwDg9gTgLgB...

Entity/Service Definitions

import { Entity } from "electrodb";

const tasks = new Entity(
  {
    model: {
      entity: "tasks",
      version: "1",
      service: "taskapp",
    },
    attributes: {
      id: { type: "string" },
      expiresAt: { type: "string", default: () => new Date().toISOString() },
      localFieldName: {
        type: "number",
        field: "TTL", // This should be used when updating
        watch: ["expiresAt"],
        set: (_, { expiresAt }) => Date.parse(expiresAt),
      },
    },
    indexes: {
      byId: {
        pk: { field: "PK", composite: ["id"] },
        sk: { field: "SK", composite: [] },
      },
    },
  },
  { table: "taskapp" },
);

tasks.create({ id: "test" }).go();

// Updating `expiredAt` triggers an update of `localFieldName`, which itself
// should be saved as `TTL` based on the `field` attribute, but it's saved as
// `localFieldName` to dynamodb
tasks.update({ id: "test" }).set({ expiresAt: new Date().toISOString() }).go();
@sam3d sam3d changed the title Watched attributes ignore field property update Computed attributes ignore field property during update Aug 19, 2023
@tywalch
Copy link
Owner

tywalch commented Aug 19, 2023

Thank you! I will make this a priority!

@tywalch
Copy link
Owner

tywalch commented Aug 19, 2023

This a great find 👍

@tywalch
Copy link
Owner

tywalch commented Aug 19, 2023

I have addressed this issue in version 2.8.2, let me know if that fixes your issue 👍

@sam3d
Copy link
Sponsor Author

sam3d commented Aug 19, 2023

Wow that was so fast 😱 That works perfectly for me now, thank you so much !!

@sam3d sam3d closed this as completed Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants