Postgres Queries have wrong where clause
Recently we some read actions do not return the correct data, the Queries that are logged have an obviously wrong where clause
The clause should be
c0."id" = ?
with the id in the parameter list
This is the resource and we query the current_user graphql query
We could also observe this behaviour when loading a has_one relationship
Versions:
ash: 06329b97cf531b6b585630638028233a48a7fa0b
ash_graphql: c70e7dec7dac1aac7fd40a67b51a6d61d67f9d41
ash_postgres: 9e31f905861c8f97bb2b54fd8604eb362391e67525 Replies
In the case of the user we found that there is a problem with the embedded resource, if the attribute features is NULL in postgres the api returns null as the user, if there is a value in the column it returns the user. We can also get the user with the null in features if we exclude it in the graphql Query.
On the relationship side, we only get the relationship if we have also included the foreign key in the graphql query.
🤔 so that soudns like maybe two bugs
hmmmmm....
have you reproduced this in code?
skipping
ash_graphql
I mean
ohhhhhhhnot without it no
I think I see at least one problem, maybe
one sec
got one of these reproduced in test
the nil attribute
okay can you try ash
main
on it
looks good after quick check
I'm still unable to reproduce the relationship one in a test, still trying though 😉
wait
maybe I don't understand
are you saying that there is still an issue?
yes, the second problem is still there.
let me describe it again:
If I query the api like this
I get this back
but if I do
i get this back
okay, will look into it.
Thanks
I checked the Query from the FE again and it seems that it has to do something with fragments
This is the actual query that the frontend sent.
with the fragment inlined it works
or adding the
ownerId
in the fragment also worksokay, thanks for the info
i can probably fix it with that
amazing
hmm....actually still trying to reproduce this
oh there is a difference
That also works for me currently
Is there anything special about order/owner/the relationship between them I should know about?
Not sure, I checked a couple other fragments we have in the fe, we do have other fragments with relationships that work. But the other ones i saw were all has_many relationships, this one was a has_one. I tried switching has_one with belongs_to because i thought I might have it configured wrong, but that didn't change anything.
I thought that maybe it would only trigger the error with the Postgres DataLayer because I assumed that the ETS DataLayer might always return all the fields instead of only the selected ones. So i tried using AshPostgres in the test from AshGraphql and add the fragment but I was unable to reproduce there too.
I also had the relationship declared only on the first resource offer -> owner, I then added the reverse declartion too, but I that didn't change anything either.
The resources are in different AshApi/Registries
I inspected the query https://github.com/ash-project/ash_postgres/blob/9e31f905861c8f97bb2b54fd8604eb362391e675/lib/data_layer.ex#L606
and in the were clause you can see that there is no Id in the array. But I didn't quite figure out how ash got there^^
🤔 🤔
So inside AshGrapqhl https://github.com/ash-project/ash_graphql/blob/c70e7dec7dac1aac7fd40a67b51a6d61d67f9d41/lib/graphql/resolver.ex#L1901
we get the fragment name as identifier.
field_or_relationship: [resource: JdlEngine.Offer.Resources.Offer, identifier: "Owner"]
field_or_relationship: nil
GitHub
ash_graphql/lib/graphql/resolver.ex at c70e7dec7dac1aac7fd40a67b51a...
An absinthe backed graphql API extension for the Ash Framework - ash_graphql/lib/graphql/resolver.ex at c70e7dec7dac1aac7fd40a67b51a6d61d67f9d41 · ash-project/ash_graphql
I was now able to reproduce the issue and add a test to ash grapqhl
https://github.com/ash-project/ash_graphql/pull/80
GitHub
reproduce fragment issue by barnabasJ · Pull Request #80 · ash-proj...
I was now able to reproduce the issue with the fragment. The fragment needed to be on a lower level in the query and the related resource was not allowed to be queried further up.
At the top, the t...
Amazing as always 🙂
I’ll address this today.
Thank you
okay, got a fix incoming
Should be fixed in main 🥳
🚀 will probably check it out tomorrow
Queries look good on our end too.
During testing I also tried updating ash to the latest commit on main, but I'm getting compile errors
Interesting…update spark as well
Ill push a fix to a new RC
oh, interesting
it looks like it does depend on the latest spark...
oh, I bet you're doing this
which was actually a bug that it was supported
we've actually kinda figured that out, realized we can support it easily. I'll push rc.1 that supports that syntax and then you can upgrade
so I just need to put the calc after the type instead of the do block right?
after you wrote this i remember i had a similar problem once, where i had the option specified at the top and inside the do block and I was wondering why it was not working because the one in the do block overwrote the outer one.
It should work without it inside the do block now
Using rc 1
I am having an issue with the generated SQL when using a filter expression on a resource with a filter.
Does anyone know why the where (FALSE) is being generated?
:resource_type == "Task"
:resource_type
is a value, not a reference
:resource_type == "Task"
is always false
You are looking for filter expr(resource_type == "Task")