Error loading aggregate when resource has a relates_to_actor_via policy
Hi Folks, I have encountered an issue when trying to load a count aggregate. The conditions to reproduce seem to be:
- DataLayer is Postgres
- Resource has a relates_to_actor_via policy on read
- The relates_to_actor_via path includes a has_many relationship
- An aggregate is loaded
I tried to debug this down in the authorizer / check layers however was not able to figure it out so far. I've created a failing test on ash_postgres https://github.com/ahey/ash_postgres/commit/f290ae47b83aa2c1148978327d970fe38ec5000b
GitHub
Add failing test for policy + aggregate issue Β· ahey/ash_postgres@f...
The conditions for this issue to occur seem to be:
- DataLayer is Postgres
- Resource has a relates_to_actor_via policy on read
- The relates_to_actor_via path includes a has_many relationship
- A...
12 Replies
Hey, thanks for the report! Will look into this ASAP (tomorrow)
And thank you so much for the failing test. Will almost certainly allow me to fix it quickly π
Thanks Zach, itβs a complex set of conditions to set up, figured it would be a pain to debug without a test π
Alright, pushing a fix up, will verify it on a few projects and release. Great find and excellent report πββοΈ
Latest releases of ash and ash_postgres should see this issue resolved π
Thanks so much for this Zach, it looks great. Before I can fully test I encountered one more issue, which I have raised separately.
This is working beautifully, including via the GQL layer which is where I originally discovered the issue. Thank you for your help!
πglad to help!
I have encountered an issue related to this one. In case there is a policy using relates_to_actor_via on the resource being aggregated, an error is generated when loading the aggregate.
Note that I encountered the issue when testing via the GQL layer, however was able to reproduce it without GQL being involved.
Details and failing test here: https://github.com/ahey/ash_postgres/commit/1dbd7f619d567167af76d058eb0647d76f7c699c
GitHub
Update test to demo issue with policy on aggregate Β· ahey/ash_postg...
The issue occurs when an aggregate is loaded, and the aggregated
resource itself has a relates_to_actor_via policy.
The following error is produced at test/aggregate_test.exs:42
1) test relates...
Will take a look in the AM π
Hey @Alan Heywood that issue should be resolved now π
Will mark this as solved for now since the provided test passes. Feel free to reopen it if you encounter the issue still. Once again, its always a pleasure to fix the bugs you report because you're always so thorough and provide test cases, such a wonderful thing for me π
Thank you @Zach Daniel, it's my pleasure. I have confirmed that this fix has worked in my codebase, and also via my GQL layer π₯³
However, I did get a fright when I attempted to load the aggregate after the record is read via Api.load! β the same error occurs. It's not a problem for me as I can avoid doing that, however if this is something you would like to fix I am happy to push the failing test.
Yes, that would be great!
GitHub
test: demonstrate issue loading aggregate Β· ahey/ash_postgres@09092cc
Calling Api.load! to load an aggregate on an existing record, where
the aggregated record has a relates_to_actor_via policy on it causes
the following error. Note that this error was recently fixed...
Alright, should be fixed in main again π
Wonderful, thank you once again! Current status of my project:
159 tests, 0 failures