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

SQLITE hangs when updating M2M relationships with one_deselect_action=delete #10462

Open
3 tasks done
eikaramba opened this issue Dec 12, 2021 · 3 comments
Open
3 tasks done
Labels
API Bug DB: SQLite Good First Issue

Comments

@eikaramba
Copy link

@eikaramba eikaramba commented Dec 12, 2021

Preflight Checklist

Describe the Bug

sqlite hangs due to multiple transactions at the same time
see also

#6888

To Reproduce

Follow https://docs.directus.io/getting-started/installation/cli/ starter guide

  1. use sqlite
  2. start directus and create 2 data models (add name text field to both to be able to save data)
  • posts
  • tags
  1. create m2m model between the 2 upper models (tags has posts, posts has tags)

  2. allow public role ALL CRUD operations

  3. set on deselete action to cascase to posts.tags field
    grafik

  4. add 1 item into each model (just add name)

  5. execute

PATCH http://localhost:8055/items/posts/1
{
    "name":"post name changed",
    "tags":[
        {"tags_id":1}
        ]
}
  1. server hangs

Errors Shown

No response

What version of Directus are you using?

9.2.2

What version of Node.js are you using?

16.6.1

What database are you using?

SQLITE

What browser are you using?

FF

What operating system are you using?

win64

How are you deploying Directus?

locally

@eikaramba eikaramba added the Bug (Potential) label Dec 12, 2021
@eikaramba eikaramba changed the title M2M patch results in ghost entries SQLITE hangs when updating M2M relationships with one_deselect_action=delete Dec 12, 2021
@eikaramba
Copy link
Author

@eikaramba eikaramba commented Dec 12, 2021

i wanted to try to avoid the ghost entries which happen when you update the item with a new relation, as you see above. then the old entries always remain in the database, thus i thought i might update to cascade. but unfortunately it seems directus is then maybe trying to delete everything and is doing this in multiple transactions which sqlite does not support (this is only my guess)

if using the cascade on deselect is not recommended, then how can i avoid these ghost entries which happen upon setting new relationships when updating the item?

@eikaramba
Copy link
Author

@eikaramba eikaramba commented Dec 12, 2021

in regards to the clean up i am now using a action. but honestly this feels wrong

action("posts_tags.items.create", async ( {payload,key}, { accountability,schema,database }) => {
    //clean up
    const junctionServiceAdmin = new ItemsService("posts_tags",{ schema, knex: database });
    await junctionServiceAdmin.deleteByQuery({ filter: { _or:[{posts_id: {_null:true} },{tags_id: {_null:true} }]}});
  });

@rijkvanzanten rijkvanzanten added API Bug DB: SQLite Good First Issue and removed Bug (Potential) labels Dec 13, 2021
@rijkvanzanten
Copy link

@rijkvanzanten rijkvanzanten commented Dec 13, 2021

if using the cascade on deselect is not recommended

It is! How you're configuring it is the recommended approach. I'm assuming it's simply a case of the wrong transaction connection being used somewhere in this flow 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Bug DB: SQLite Good First Issue
Projects
None yet
Development

No branches or pull requests

2 participants