-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Failure while raising QueryError in assert_subquery_fields! #4419
Comments
Thanks for the report @rbino. Are you able to provide a query and Repo function call that generates the issue? That will be easier for us to play with and investigate. |
I've pushed a branch to help reproduce the problem. Run a docker run -it --net=host --rm -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=postgres postgres Then use the repo: git clone https://github.com/rbino/ash_postgres.git -b relationship-count-ecto-debug
cd ash_postgres
mix deps.get
mix test.reset
mix test test/load_test.exs:788 This runs only the specific test that was triggering the error |
Thanks for the repo, it was very helpful. I'm not familiar with Ash but from my debugging it seems like you are running a subquery where this is part of the select statement: %{
aggregates: %{
aggregate_0:
type(
coalesce(
type(as(1).aggregate_0, {:parameterized, Ash.Type.Integer.EctoType, []}),
type(^0, {:parameterized, Ash.Type.Integer.EctoType, []})
),
{:parameterized, Ash.Type.Integer.EctoType, []}
)
}
} For subqueries Ecto doesn't allow the values to be a map, in this case the value of It seems there is something not working nice with atoms, structs, maps, lists, tuples and sources are not allowed as map values in subquery .... This might be something @josevalim needs to take a look at in elixir. For reference, this is the expression causing the issue: {:%{}, [],
[
aggregates: {:%{}, [],
[
aggregate_0: {:type, [],
[
{:coalesce, [],
[
{:type, [],
[
{{:., [], [{:as, [], [1]}, :aggregate_0]}, [], []},
{:parameterized, Ash.Type.Integer.EctoType, []}
]},
{:type, [],
[{:^, [], [0]}, {:parameterized, Ash.Type.Integer.EctoType, []}]}
]},
{:parameterized, Ash.Type.Integer.EctoType, []}
]}
]}
]} |
|
We do some pretty crazy stuff under the hood in our query builder to build these kinds of things. It makes sense that this would not be possible. With the exception (possibly) of the error message, I don't think that this is something that needs to (or could be) fixed in ecto. What we'll need to do is flatten those out with some indicator we can use to expand them again, like As for generating the type, I'm pretty sure that we do that always with |
Digging deeper this is certainly an Ecto bug. We cannot call Thoughts @greg-rychlewski? |
I'm cool with that change, just want to keep in mind that we do manually construct |
I was going to say I prefer making it valid AST because I believe that's what we try to do for all the other query expressions. Zach's message made me wonder where people might be using this though...the only public place I could find related to this is the function If I'm not missing anything about public APIs then I would prefer making it valid AST. It's consistent with the rest of the query handling and it just works™. |
I can get ahead of it in advance and make sure that we only produce these values w/ |
I'm wondering if this will be in the next patch release? I know libraries such as Instructor rely on the previous version (3-tuple), so would this be considered a breaking change / be a minor release? Or is this considered a private API and thus the change could happen in a patch? Curious because my schema validation library Flint also matches on this. Thanks! |
Hasn't it already been released? AFAIK this is considered a private API and was changed in a minor release. |
Looks like I'm wrong and it hasn't been released :) |
Oh maybe it has been. I've been working from main for Flint since Im depending on the EDIT: Just saw your response right after I sent this comment |
It will be there on v3.12. Probably happening sooner than later, let me start with a CHANGELOG. |
Appreciate the reply! |
Elixir version
1.16.2
Database and Version
PostgreSQL 15.4
Ecto Versions
master, commit a8cd6ac
Database Adapter and Versions (postgrex, myxql, etc)
Postgrex 0.17.5
Current behavior
I was investigating a failure while working on a new feature in Ash. The code failed on a rather obscure point (a
FunctionClauseError
deep inCode.Normalizer
).Ecto.Query.Planner
was removing its portion of the stacktrace so I've started digging to find the cause of the error.The error bubbles up from the call to
Macro.to_string/1
here.These are the arguments passed to the function (printed with
IO.inspect(binding())
:This is the original stacktrace (without the filtering from
Ecto.Query.Planner
:Expected behavior
Not sure if this is a problem in
Macro.to_string
or maybe in the original expression. The expected behavior is that raising an error should not to trigger another error obfuscating the original one (possibly even with malformed expressions).The text was updated successfully, but these errors were encountered: