Repository navigation
868 bug/resource based inline aggregates failing from differing targets - #889
Conversation
…esource-based-inline-aggregates-failing-from-differing-targets
…esource-based-inline-aggregates-failing-from-differing-targets
|
👋 thanks! Would you mind finding a good test for this among the existing test files? There should be like an "aggregates test". Thanks 🙇 |
|
Hi, Zach! Just double checking, you need a test in ash_sql as well that checks for aggregations. Is that correct? Also, would you like that as a new pull request, or just add it to the same branch as this one? |
|
Nope, just a test in ash_postgres |
|
This PR already contains a test for the specified bug. Would you like an additional test in an additional file for this same bug as well? Just want to make sure we are on the same page. |
|
Sorry, what I meant was that this PR contains a test in its own file, but in general we prefer to keep tests organized into fewer files. So if you could find a good other file to put this test in that would be great :) |
|
Same page status acquired! The regression test now lives in test/aggregate_test.exs. Feel free to let me know if you'd like anything else changed. |
|
🚀 Thank you for your contribution! 🚀 |
Fix For Inline First Aggregate Mismatch
Contributor Checklist
Description
This is a fix to address the resource-based inline aggregates (issue 868) for the posgres_sql repository.
Problem
Whenever a guest schema and table are passed into the first macro, the resulting query attempts to look up the guest table from the local schema, resulting in a mismatch followed by a crash. So far, I've observed this only happening with the first macro only.
The cause is that when the query is generated, the guest table name is kept, but the schema is forgotten completely. This causes the guest table to be auto assigned to the local schema instead, resulting in a crash.
calculate :latest_report, :string, expr(first(Report, field: :title, query: [ filter: expr(author_name == parent(name)), sort: [inserted_at: :desc] ] ))Solution
The function resource_to_query in lib/query.ex is now configured with the prefix already assigned to the target schema instead of being set to null. This way, the query generated by this starts out correct and does not need to be corrected later down the line. Any functions that need to override this down the line can still do so.
What this PR Includes
This PR are includes the regression test for this bug (test/inline_first_aggregate_schema_test.exs). The test reproduces the code scenario displayed above.
The the bug fix for this test can be found here.