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

Item take revision of other item on updateMany #17091

Open
rmarquet21 opened this issue Jan 11, 2023 · 6 comments
Open

Item take revision of other item on updateMany #17091

rmarquet21 opened this issue Jan 11, 2023 · 6 comments

Comments

@rmarquet21
Copy link

Describe the Bug

I noticed when I want to edit multiple items at the same time from the interface, I have a switch of revision between different item updated.

Item Id -> 1 take revision of Item Id -> 2
Item Id -> 2 take revision of Item Id -> 1

Strangely, this problem only happens with multiple update on the interface and on certain items.

To Reproduce

  1. Create collection with status field (with default values)
  2. Using your NodeJS lib v10.1.2, create multiple items in this collection.
import { Directus } from '@directus/sdk';

const client = new Directus(/* ... */);

client.items('sample').createMany([
{
  status: 'draft',
  things: 'example1',
},
{
  status: 'draft',
  things: 'example2',
},
{
  status: 'draft',
  things: 'example3',
},
]);
  1. Update the status to Published on directus:
    image

  2. You will see the expected revision for item with ID 505338:
    image

  3. Update something of this item and the problem is resolved:
    image

Errors Shown

No response

What version of Directus are you using?

9.20.4

What version of Node.js are you using?

12.22.12

What database are you using?

Postgres

What browser are you using?

Chrome

How are you deploying Directus?

Docker

@github-actions
Copy link

Linear: ENG-460

@azrikahar
Copy link
Contributor

This reminds me of #12460, but not sure are they related since that was a few versions ago. With that said, would you mind checking whether it is still unresolved on the latest version? which should be 9.22.2 as of the writing of this comment.

Can you try reproducing this on a fresh Directus instance with fresh db as well? Are you using autoincrement integer as primary key or something else? I'm curious why the ID shows up, but perhaps you are just setting it to not be hidden and not actually editing the IDs?

@rmarquet21
Copy link
Author

IDs from other table, I don't have autoincrement, but his unique.

And to develop in update made the changes are not displayed, only in revision preview we can see that we are not in sync with the right item.

(All screens come from the same item)

Update Made:
image

Revision Preview:
image

Actual item data on directus:
image

@HugoMuller
Copy link

Hi @azrikahar,

I'm working with @rmarquet21 and to elaborate a little bit:

This reminds me of #12460, but not sure are they related since that was a few versions ago. With that said, would you mind checking whether it is still unresolved on the latest version? which should be 9.22.2 as of the writing of this comment.

Yes, it is extremely similar, and it might be the same bug actually: updating items one by one using .updateOne() is fine. But updating many items at once with .updateMany() seems to corrupt the revisions of all the items being updated.

Are you using autoincrement integer as primary key or something else? I'm curious why the ID shows up, but perhaps you are just setting it to not be hidden and not actually editing the IDs?

We do not use autoincrement IDs as primary key. We are using pre-defined IDs from another knowledge base.
The ID shows up because it is actually not hidden in the UI, but it is NOT edited during our process.

Can you try reproducing this on a fresh Directus instance with fresh db as well?

Yes. I just updated our docker container to the latest version 9.22.4, and I'm using the JS SDK 10.1.2 (not the latest but that's OK here I guess).
To reproduce:

  1. create a basic collection named sample:
    • an id column as primary key (I think that ID strategy does not matter, but you can use unique integer without autoincrement, to stick with our schema, as below)
    • status column as suggested by Directus
    • create/update dates
    • a text field things (just to illustrate our use case)

Screenshot 2023-02-06 at 14 58 59

Screenshot 2023-02-06 at 14 59 09

(Yes, we forgot to set the ID to Readonly, this is a mistake... but I assure you that the IDs are never pushed during updates.)

  1. insert items in the collection:
import { Directus } from '@directus/sdk';

const client = new Directus(/* ... */);

await client.items('sample').createMany([
  {
    id: 1,
    status: 'draft',
    things: 'example1',
  },
  {
    id: 2,
    status: 'draft',
    things: 'example2',
  },
  {
    id: 3,
    status: 'draft',
    things: 'example3',
  },
]);
  1. Now update items one by one:
await client.items('sample').updateOne(1, {
  status: 'approved',
  things: 'new example1'
});
await client.items('sample').updateOne(2, {
  status: 'approved',
  things: 'new example2'
});
await client.items('sample').updateOne(3, {
  status: 'approved',
  things: 'new example3'
});

At this point, new revisions are OK: we have the correct status, things and ID values. No corruption so far.

  1. Then update the 3 items at once:
await client.items('sample').updateMany([1, 2, 3], { status: 'published' });

The data is still correct in sample collection, as expected. But if you look at the last revision created for each item, you can see that the IDs have been interchanged with each other: the revisions are corrupted.

  1. Re-updating the items one by one (like in step 4) fixes the issue

Corrupted revisions break our entire process, as we use them to display the latest published version of each item, ignoring newer drafts waiting for a review, before being published.
As a workaround, we could update items one by one, but this will badly impact our performance and defeat the point of having a batch update.

I hope this is enough information to help you solve this issue 😇

@paescuj
Copy link
Member

paescuj commented Apr 19, 2023

/linear

@github-actions
Copy link

🤖 Linear issue created! Maintainers can access it here: ENG-905

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋 Backlog
Development

No branches or pull requests

5 participants