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

The action hook event is not up to date with the schema #11421

Open
3 tasks done
roceroo opened this issue Feb 3, 2022 · 8 comments
Open
3 tasks done

The action hook event is not up to date with the schema #11421

roceroo opened this issue Feb 3, 2022 · 8 comments
Assignees
Labels
API Bug Good First Issue

Comments

@roceroo
Copy link

@roceroo roceroo commented Feb 3, 2022

Preflight Checklist

Describe the Bug

When I try to create a new field in a recent created collection, the schema when the hook is fired (action) is not up to date with what the schema should look like

To Reproduce

create a action hook, try to log the collections from the context schema, create a collection in the app, the new collection will not show at the schema

Errors Shown

No response

What version of Directus are you using?

9.5.0

What version of Node.js are you using?

16.13.1

What database are you using?

sql

What browser are you using?

chrome

What operating system are you using?

windows

How are you deploying Directus?

Docker

@roceroo roceroo added the Bug (Potential) label Feb 3, 2022
@rijkvanzanten
Copy link

@rijkvanzanten rijkvanzanten commented Feb 3, 2022

What action hook are you using?

@rijkvanzanten rijkvanzanten added Needs More Info and removed Bug (Potential) labels Feb 3, 2022
@roceroo
Copy link
Author

@roceroo roceroo commented Feb 3, 2022

I'm using 'collections.create'
a friend of mine found this snippet that might be source of the issue (cache)
image

@roceroo
Copy link
Author

@roceroo roceroo commented Feb 3, 2022

action('collections.create', async ({ key: collection }, { accountability }) => {
    const { FieldsService } = services
    const schema = await getSchema()

    const fieldsService = new FieldsService({
      knex: database, schema, accountability: { ...accountability, admin: true }
    })

    const fieldOptions = {
      field: 'slug',
      type: 'string',
      meta: {
        interface: 'input',
        readonly: true
      }
    }

    try {
      await fieldsService.createField(collection, fieldOptions)
    } catch (error) {
      console.log(error);
    }
  })

This is the code I was trying, if the schema was up to date, the new collection should show at the schema @rijkvanzanten

@roceroo
Copy link
Author

@roceroo roceroo commented Feb 3, 2022

action('collections.create', async ({ key: collection }, context) => {
    const schema = await getSchema()
    console.log(schema, collection, !!schema.collections[collection]);
  })

if you try to run this code, you'll see that the new collection is not at the schema

@rijkvanzanten rijkvanzanten added API Bug Good First Issue and removed Needs More Info labels Apr 7, 2022
@BranAndSceolan
Copy link

@BranAndSceolan BranAndSceolan commented Apr 19, 2022

Hello!
I would like to try solving this issue.

@BranAndSceolan
Copy link

@BranAndSceolan BranAndSceolan commented Apr 21, 2022

Sadly I had some problems getting directus to run on my pc. Since I don't have time right now to find out why, I'll unasign myself.
If in the future there is still no solution and I got directus working on my pc I might come back to this.

@ykabusalah
Copy link

@ykabusalah ykabusalah commented May 1, 2022

Hello, could I claim this issue and attempt fixing it?

@benhaynes
Copy link
Sponsor

@benhaynes benhaynes commented May 2, 2022

Of course! We've assigned you, feel free to reach out over Discord if you have any questions along the way.

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

No branches or pull requests

5 participants