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

[Entity] Buggy Behavior of upsertEntities #518

Open
Char2sGu opened this issue Apr 14, 2024 · 3 comments
Open

[Entity] Buggy Behavior of upsertEntities #518

Char2sGu opened this issue Apr 14, 2024 · 3 comments

Comments

@Char2sGu
Copy link
Contributor

Which @ngneat/elf-* package(s) are the source of the bug?

entities

Is this a regression?

No

Description

When upserting an array of entities, where some entities do not yet exist but were repeated in the array, the upsertion will result in the same id being added to the ids array for multiple times.

https://github.com/ngneat/elf/blob/9dbc51d5e36233fab81128072354548facb26256/packages/entities/src/lib/update.mutation.ts#L229C1-L239C6

    for (const entity of entitiesArray) {
      const id: getIdType<S, Ref> = entity[idKey];
      if (hasEntity(id, options)(state)) { // <-- This should be `hasEntity(id, options)(state) || updatedEntitiesId.includes(id)`
        asObject[id] = { ...state[entitiesKey][id], ...entity };
        updatedEntitiesId.push(id);
      } else {
        ids.push(id);
        asObject[id] = entity;
      }
    }

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in

No response

Anything else?

No response

Do you want to create a pull request?

Yes

@Char2sGu
Copy link
Contributor Author

I can create a PR if this is confirmed a bug

@NetanelBasal
Copy link
Member

Seems like a bug, you're welcome to create a PR. Thanks

@mhosman
Copy link

mhosman commented Aug 27, 2024

I also see that the upsert is not always working. Right now I have an object that changed after a request, and after the upsert, the data inside of it is not changing.

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

3 participants