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

Switching collection from "Single Object" to normal breaks the collection display #7990

Closed
3 tasks done
infomiho opened this issue Sep 13, 2021 · 6 comments · Fixed by #8184
Closed
3 tasks done

Switching collection from "Single Object" to normal breaks the collection display #7990

infomiho opened this issue Sep 13, 2021 · 6 comments · Fixed by #8184
Assignees
Labels

Comments

@infomiho
Copy link

Preflight Checklist

Describe the Bug

Switching a collection from single object to normal collection breaks the API.

To Reproduce

  1. Create a new collection
  2. Set "Use as a single object" to true
  3. Add some data
  4. Change the "Use as single object" to false

Here is a video with repro as well https://youtu.be/1LTC2vPtrdw

What version of Directus are you using?

9.0.0-rc.92

What version of Node.js are you using?

v12.20.2

What database are you using?

Postgres 12

What browser are you using?

Chrome

What operating system are you using?

Linux

How are you deploying Directus?

Kubernetes

@infomiho
Copy link
Author

infomiho commented Sep 13, 2021

Just to add to discussion, it might be related to scaling the deployment to two instaces.

I'm not sure why the inconsistency happens when using two separate instances connecting to the same DB. I'll investiage and post more details soon.

@rijkvanzanten
Copy link
Member

@infomiho Are you using a shared provider for the cache? Like redis or memcached

@infomiho
Copy link
Author

infomiho commented Sep 14, 2021

@rijkvanzanten Hey I've tried the same steps locally with running Docker and the same thing happens.

I've disabled any form of caching. This is the env I'm using.

ADMIN_EMAIL: "${ADMIN_EMAIL}"
ADMIN_PASSWORD: "${ADMIN_PASSWORD}"
PUBLIC_URL: "${PUBLIC_URL}"

Also, switch back and forth between the types of collection, the previous data gets stuck.

EDIT: One thing I discovered when I look at the response of http://localhost:8055/collections?limit=-1 I can see that in the meta prop for the collection test the prop singleton is true.

But the http://localhost:8055/items/test returns a list of objects. Which would indicate there is a sort of a mismatch.

@infomiho
Copy link
Author

infomiho commented Sep 14, 2021

This seems related to CACHE_SCHEMA since after clearing the caches manually by using the POST http://localhost:8055/utils/cache/clear it all works again.

After inspecting the source code, it seems that schema cache is never cleared. Given that collection props like singleton can change on the fly, we should consider clearning the schema cache after editing collection props.

Prehaps calling schemaCache.clear() on this line https://github.com/directus/directus/blob/main/api/src/controllers/collections.ts#L87

@rijkvanzanten
Copy link
Member

After inspecting the source code, it seems that schema cache is never cleared.

This is not entirely true. The schema cache is cleared in various operations:

if (this.schemaCache) {
await this.schemaCache.clear();
}

That being said, it seems like it's not clearing it on update of a collection, which is an oversight 👍🏻

@infomiho
Copy link
Author

Thanks man!

Sorry, I didn't mean to come off as saying you never cleared the cache, I just didn't find it with my primitive search, that's all 🙂

@azrikahar azrikahar self-assigned this Sep 21, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants