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
Failing to apply snapshot schema when altering field sort order #17820
Comments
Not a solution but a report of a similar error in hopes it helps narrow down debugging efforts: I saw this error yesterday also, but under slightly different circumstances. I unfortunately haven't had time to work out the minimal reproduction steps. My usecase for directus might be slightly abnormal, as I manage my postgres data schema with a separate db migration tool so I can keep my schema in code/version control. I then rely on directus introspection and some manual tinkering of field config to make the UI user friendly. I was trying to replicate my prod instance locally, with steps:
Due to time constraints I had to revert back to 9.22.4, where things seem to work okay. I tried dumping the snapshot schema from both directus 9.22.4 and 9.23.1, with neither being applied successfully by 9.23.1. |
/linear |
🤖 Linear issue created! Maintainers can access it here: ENG-827 |
Related issue #17832 |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
So, I've been digging into this a bit, it doesn't seem limited to just sort order. The issue looks like it comes up whenever a primary key has any sort of metadata change, for example - change from hidden to visible. What's happening is that in fieldsService.updateField a schema comparison is being made here This comparison always fails because the object returned from the schemaInspector and the hookAdjustedField.schema is different - not meaningfully, but there are extra fields that are set to null, so there's a false detection of schema change. Next, because this fails, the knex alter() call is issued to attempt to modify the schema to match. Well, the alter() call definitely shouldn't be invoked on a metadata change, but what's more, alterNullable defaults to true. When the SQL gets generated this completely blows up on a primary key field, because you can't make that nullable, hence the "alter column "id" drop not null - column "id" is in a primary key" error you're seeing. @rijkvanzanten hope this helps debug and resolve the issue. |
@claytongulick Thank you very much! That's certainly going to be helpful! We're about to investigate this one as well 👍 (May I kindly ask you not to randomly ping team members?) |
Sure thing, sorry - have had lots of discussions with Rijk and don't know how y'all get notified internally - this one was a couple weeks old, so wanted to mention that I'd dug into it a bit to hopefully save someone some time. Won't happen again 😄 |
No problemo, just wanted to have it mentioned & thanks again ❤️ In general it should be enough to just post in the threads, in most cases the right person will be notified, otherwise we'll forward it internally 👍 |
Checklist
Describe the Bug
Getting this exception (
articles
is a data model):It happens after only altering the visual order of a field, i.e. when using drag-and-drop and then updating the schema snapshot file to be shared with other developers. I'd expect that just altering
sort
would not cause a database schema change since it's just a value in thedirectus_fields
table.I'm not 100% certain no other issues also encounter this, but similar stack traces refer to other possible causes.
To Reproduce
I've setup a repository to reproduce the issue. You can find it here https://github.com/smonn/repro-directus-snapshot-issue
Hosting Strategy
Self-Hosted (Custom)
The text was updated successfully, but these errors were encountered: