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
Cannot read property 'field' of null #7247
Comments
It's using this second query to fetch the primary keys: directus/packages/schema/src/dialects/postgres.ts Lines 33 to 48 in 27037f9
Does your collection have an index for the primary key? For example, this is what the primary key index would look like by default: |
Related to #6279 |
@rijkvanzanten Everything is set up correctly. Index is there, primary key is there
I cannot find anything at db level that might be misplaced |
@darioguarascio Could you send over a dump of just that exact table + column + index combo? That should make it super easy to reproduce and fix 🙂 |
@rijkvanzanten I hope this is enough. here a
and queries:
|
That's perfect, thanks! |
Hmm, I just ran your sql dump to add the table to my instance, and everything seems to show up as expected: And was able to create a new item without issues too: I think the root cause of the problem might be something else than the primary key of this particular table 🤔 Would you be able to share a full dump of everything either here or through rijk@directus.io? |
@rijkvanzanten I managed to solve the problem by dropping 3 extra indexes that involved
by dropping them, My guess is that when the primary key is involved in other indexes (maybe unique ones, even if it makes no sense but pg allows it) this could create conflicts in the pk recognition. I hope it helps here the schema of mentioned columns
|
One of those classic super-edge cases that are impossible to reproduce. |
@darioguarascio If you could send over a full pg_dump of everything (including the directus_ system tables), I should be able to see the same error 🤔 (If you need to send it in private, you can email it to rijk@directus.io) I think you're very close by mentioning the multiple indexes, as there is another known problem around the subject (#6204), but we can't know for sure without an accurate reproduction of course 🤔 |
@rijkvanzanten unfortunately I cannot send the full dump as it's a production db. |
So just to confirm 100%, this is the confirmed way to make the error disappear/show up again?
Just trying to think through other ways I can reproduce this on my end.. We tried the above, so there must be something i'm missing here 🤔 |
@rijkvanzanten Not sure if this is the way, but dropping the 3 extra indexes helped getting back to normal. |
Gotcha. Strange that I can't get the same error to pop up using the dumps of the indexes provided above.. Can you reproduce the error on a fresh installation with the SQL you provided above? |
@rijkvanzanten I got this issue all the time with PostgreSQL (AWS RDS) I also can't reproduce it in my local as well. the workaround that I found is to REINDEX the whole database and it temporarily fixed the problem. |
I just tried reproducing it again using the instructions available, but still aren't able to get the original issue to show up.. I'll have to close this for now. Once a clear way to reproduce the error is available, we can reopen and reinvestigate. |
Thank you for taking the time to submit this! Unfortunately, our team was not been able to reproduce it based on the information provided. Therefore, we will close this ticket for now, but will happily re-open it if new details are provided that allow us to reliably replicate the problem. As a reminder:
This is an automated response. |
Preflight Checklist
Describe the Bug
I suspect there are issues identifying the primary key of some specific tables, which cascades to more complex issues that i cannot point out exactly.
I use postgres as database, one table which I imported out of directus had a primary key set but not using as default
nextval()
.I found out this snippet in the code that made me believe this is how the pkey is identified
column.default_value?.startsWith('nextval(')
in https://github.com/directus/directus/blob/27037f95c7dae030d656d7a7ca1f30832b347211/packages/schema/src/dialects/postgres.tsand even after manually setting the column value defaulting to it ( with an
ALTER TABLE
statement ), directus cannot recognize the primary key of such table (proof is, in data model there is no key icon onid
field and in api calls,is_primary_key
isfalse
Is there a better way to let directus detect a primary key?
Possible consequences of this issue:
To Reproduce
Dropping the
nextval()
default value of a primary keyWhat version of Directus are you using?
9.0.0-rc.88
What version of Node.js are you using?
the one delivered with docker
What database are you using?
postgres:13
What browser are you using?
Chrome
What operating system are you using?
Ubuntu
How are you deploying Directus?
Docker
The text was updated successfully, but these errors were encountered: