Commit graph

116 commits

Author SHA1 Message Date
Zach Daniel
82dd14b953 chore: credo 2024-01-30 15:32:50 -05:00
Barnabas Jovanovics
fbd41407c3
test: add test that shows subquery error (#199) 2024-01-30 13:17:40 -05:00
Alan Heywood
aad5f9a182
test: add failing test to demonstrate bug with manual updates (#198) 2024-01-30 09:26:39 -05:00
Zach Daniel
4930a69b95 improvement: support count_nils expression 2024-01-29 17:17:32 -05:00
Zach Daniel
f20a07f54b improvement: support latest ash changes 2024-01-19 00:12:50 -05:00
Zach Daniel
f3ccb78f86 improvement: support join_filters on aggregates
fix: subquery relationships that have filters
2024-01-11 22:30:35 -05:00
Zach Daniel
9b5acd98f7 chore: credo, dialyzer, format 2024-01-10 08:34:23 -05:00
Eduardo B. Alexandre
d5d312de56 feat: Add unit test to check lateral joins
with custom schemas and tables
2024-01-10 08:19:10 -05:00
Zach Daniel
76e23b186f test: add some tests for aggregate refs in calcs 2024-01-10 07:22:25 -05:00
Zach Daniel
89a4363c1f improvement: support directly referencing aggregates from aggregates 2023-12-23 10:39:54 -05:00
Zach Daniel
68e2f74fe0 improvement: support aggregates using other aggregates
fix: various fixes for unnecessary aggregate additions
test: added a test to confirm context based multitenancy behavior
2023-12-22 21:14:40 -05:00
Barnabas Jovanovics
c916034931
fix: replace upsert field with source in EXCLUDED fragment (#187) 2023-12-19 15:05:05 +01:00
Zach Daniel
07499b6ec0 fix: use maps for composite_type instead of tuples 2023-11-29 10:27:10 -05:00
Zach Daniel
74ef0aa6c3 improvement: support composite_type/2 expression 2023-11-29 09:57:10 -05:00
Zach Daniel
592e79a2f9 improvement: support composite types 2023-11-27 17:47:54 -05:00
Zach Daniel
c53f1733be chore: format 2023-11-22 14:29:47 -05:00
Barnabas Jovanovics
179cee4b24
chore: add test (#184) 2023-11-22 13:37:54 -05:00
Daniel Newman
8caad3bf7d Adjust tests for updates from upstream 2023-11-21 09:25:24 -05:00
Daniel Newman
06510b2770 Error using calc to agg to calc to agg 2023-11-16 20:47:25 -05:00
Alan Heywood
af8d8dbcac test: add failing test to demo an issue with has_one calculations 2023-11-16 11:02:02 -05:00
Zach Daniel
52302046e1 fix: properly join to related references in relationship filters 2023-10-24 12:25:23 -04:00
Zach Daniel
270d8685e7 improvement: support to-one references in calculations 2023-10-09 18:57:06 -04:00
Zach Daniel
b35f8c715b improvement: add AshPostgres.Tsquery 2023-09-20 16:41:32 -04:00
James Harton
6cc88c82b4
improvement: Allow resources to opt out of the primary key requirement. (#166) 2023-09-06 01:18:57 -04:00
Zach Daniel
33eb4f9fb7 improvement: better error message for missing table config 2023-09-04 11:25:03 -04:00
Zach Daniel
eabb745fc3 chore: update tests for latest ash atomics support 2023-08-31 11:47:15 -04:00
Zach Daniel
5a4a52854b
improvement: support atomics (#165) 2023-08-28 16:18:56 -04:00
Zach Daniel
cbde3958f3 fix: properly handle ensure nsted calls to get_path are jsonb 2023-08-23 12:54:25 -04:00
Zach Daniel
99b2a5631c improvement: support in-line aggregates
fix: support non-atom named aggregates
2023-08-22 14:51:31 -04:00
Zach Daniel
d2e309c126 improvement: support the new parent/1 expr in relationships 2023-07-26 17:32:09 -04:00
Zach Daniel
c920b09277 improvement: support new distinct features from ash core 2023-07-18 14:48:35 -04:00
Zach Daniel
ed62006b3f improvement: support unary -/1 operator 2023-07-17 22:35:46 -04:00
Zach Daniel
d2e071773e improvement: support exists aggregates 2023-07-13 00:13:50 -04:00
Zach Daniel
11ad5f4d1b improvement: support at/2 expression 2023-07-12 17:05:33 -04:00
Zach Daniel
c1a630ee16 improvement: support string_split 2023-07-12 15:16:28 -04:00
Zach Daniel
ce9ca1ced2 chore: fix test bad identity 2023-06-27 19:14:30 -04:00
Tommaso Patrizi
96165a58ea
tests: added test for bulk upsert (#148)
Co-authored-by: Tommaso Patrizi <tommasop@gmail.com>
2023-05-26 23:58:04 -04:00
Zach Daniel
4a57a300da fix: handle raised errors in bulk actions 2023-05-22 21:17:30 -04:00
Zach Daniel
31fdbec62e chore: credo 2023-04-05 12:21:35 -04:00
Barnabas Jovanovics
e2ee0016ea
test: add test that reproduces dependent select problem (#136) 2023-03-31 12:12:13 -04:00
Darren Black
587182998e
improvement: Implement string_join expr (#132) 2023-02-21 10:21:53 -05:00
Zach Daniel
49b94fd183 fix: don't use :distinct when uniq? is not true 2023-02-17 15:21:50 -05:00
Zach Daniel
589fb4d620 improvement: better type casting for concat operator 2023-02-12 19:09:25 -05:00
Zach Daniel
bbb45f3622 fix: sorting on optimized first aggregates 2023-02-09 17:49:37 -05:00
Zach Daniel
8e8a308cd2 improvement: support new uniq? option on count/list aggregates 2023-02-09 16:09:44 -05:00
Zach Daniel
b41d383b47 fix: load by __order__ ascending 2023-02-07 17:43:53 -05:00
Alan Heywood
1dbd7f619d Update test to demo issue with policy on aggregate
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 to actor via has_many and with an aggregate (AshPostgres.AggregateTest)
     test/aggregate_test.exs:8
     ** (RuntimeError) Could not determined related for `exists/2` expression.

     Context Resource: %{aggregates: %{count_of_comments: #count<comments from #Ash.Query<resource: AshPostgres.Test.Comment>>}, calculations: %{}, data_layer: AshPostgres.DataLayer, public?: false, relationship_path: [], resource: AshPostgres.Test.Post, root_resource: AshPostgres.Test.Post}
     Context Relationship Path: []
     At Path: []
     Path: [:post, :organization, :users]
     Related: nil
     Expression: exists(post.organization.users, [id: "236f08bc-6a3a-4a78-9911-2c24189dafac"])

     code: |> Api.read_one!()
     stacktrace:
       (ash 2.5.12) lib/ash/filter/filter.ex:2121: Ash.Filter.add_expression_part/3
       (ash 2.5.12) lib/ash/filter/filter.ex:2037: anonymous fn/3 in Ash.Filter.parse_expression/2
       (elixir 1.14.2) lib/enum.ex:4751: Enumerable.List.reduce/3
       (elixir 1.14.2) lib/enum.ex:2514: Enum.reduce_while/3
       (ash 2.5.12) lib/ash/filter/filter.ex:295: Ash.Filter.parse/5
       (ash 2.5.12) lib/ash/filter/filter.ex:995: Ash.Filter.add_to_filter/6
       (ash 2.5.12) lib/ash/query/query.ex:1797: Ash.Query.do_filter/2
       (elixir 1.14.2) lib/map.ex:883: Map.update!/3
       (ash 2.5.12) lib/ash/engine/request.ex:650: Ash.Engine.Request.apply_filter/4
       (ash 2.5.12) lib/ash/engine/request.ex:557: Ash.Engine.Request.do_strict_check/3
       (ash 2.5.12) lib/ash/engine/request.ex:518: anonymous fn/2 in Ash.Engine.Request.strict_check/2
       (elixir 1.14.2) lib/enum.ex:4751: Enumerable.List.reduce/3
       (elixir 1.14.2) lib/enum.ex:2514: Enum.reduce_while/3
       (ash 2.5.12) lib/ash/engine/request.ex:255: Ash.Engine.Request.do_next/1
       (ash 2.5.12) lib/ash/engine/request.ex:211: Ash.Engine.Request.next/1
       (ash 2.5.12) lib/ash/engine/engine.ex:650: Ash.Engine.advance_request/2
       (ash 2.5.12) lib/ash/engine/engine.ex:556: Ash.Engine.fully_advance_request/2
       (ash 2.5.12) lib/ash/engine/engine.ex:497: Ash.Engine.do_run_iteration/2
       (elixir 1.14.2) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
       (ash 2.5.12) lib/ash/engine/engine.ex:257: Ash.Engine.run_to_completion/1
       (ash 2.5.12) lib/ash/engine/engine.ex:202: Ash.Engine.do_run/2
       (ash 2.5.12) lib/ash/engine/engine.ex:141: Ash.Engine.run/2
       (ash 2.5.12) lib/ash/actions/read.ex:170: Ash.Actions.Read.do_run/3
       (ash 2.5.12) lib/ash/actions/read.ex:90: Ash.Actions.Read.run/3
       (ash 2.5.12) lib/ash/api/api.ex:1005: Ash.Api.read_one/3
       (ash 2.5.12) lib/ash/api/api.ex:998: Ash.Api.read_one!/3
       test/aggregate_test.exs:43: (test)
2023-01-30 16:09:48 +10:00
Alan Heywood
f290ae47b8 Add failing test for policy + aggregate issue
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
- An aggregate is loaded

The following error is produced:

  1) test relates to actor via has_many and with an aggregate (AshPostgres.AggregateTest)
     test/aggregate_test.exs:8
     ** (Ash.Error.Unknown.UnknownError) ** (ArgumentError) No such entity nil found.

     code: |> Api.read_one!(actor: user)
     stacktrace:
       nil.spark_dsl_config()
       (spark 0.3.8) lib/spark/dsl/extension.ex:129: Spark.Dsl.Extension.dsl!/1
       (spark 0.3.8) lib/spark/dsl/extension.ex:158: Spark.Dsl.Extension.get_persisted/3
       (ash 2.5.10) lib/ash/filter/filter.ex:2986: Ash.Filter.do_hydrate_refs/2
       (ash 2.5.10) lib/ash/policy/check/relates_to_actor_via.ex:3: Ash.Policy.Check.RelatesToActorVia.try_eval/2
       (ash 2.5.10) lib/ash/policy/check/relates_to_actor_via.ex:3: Ash.Policy.Check.RelatesToActorVia.try_strict_check/3
       (ash 2.5.10) lib/ash/policy/checker.ex:63: Ash.Policy.Checker.do_strict_check_facts/3
       (ash 2.5.10) lib/ash/policy/checker.ex:88: anonymous fn/2 in Ash.Policy.Checker.strict_check_policies/3
       (elixir 1.14.2) lib/enum.ex:4751: Enumerable.List.reduce/3
       (elixir 1.14.2) lib/enum.ex:2514: Enum.reduce_while/3
       (ash 2.5.10) lib/ash/policy/checker.ex:9: anonymous fn/2 in Ash.Policy.Checker.strict_check_facts/1
       (elixir 1.14.2) lib/enum.ex:4751: Enumerable.List.reduce/3
       (elixir 1.14.2) lib/enum.ex:2514: Enum.reduce_while/3
       (ash 2.5.10) lib/ash/policy/authorizer.ex:790: Ash.Policy.Authorizer.do_strict_check_facts/1
       (ash 2.5.10) lib/ash/policy/authorizer.ex:372: Ash.Policy.Authorizer.strict_check/2
       (ash 2.5.10) lib/ash/engine/request.ex:550: Ash.Engine.Request.do_strict_check/3
       (ash 2.5.10) lib/ash/engine/request.ex:518: anonymous fn/2 in Ash.Engine.Request.strict_check/2
       (elixir 1.14.2) lib/enum.ex:4751: Enumerable.List.reduce/3
       (elixir 1.14.2) lib/enum.ex:2514: Enum.reduce_while/3
       (ash 2.5.10) lib/ash/engine/request.ex:255: Ash.Engine.Request.do_next/1
       (ash 2.5.10) lib/ash/engine/request.ex:211: Ash.Engine.Request.next/1
       (ash 2.5.10) lib/ash/engine/engine.ex:650: Ash.Engine.advance_request/2
       (ash 2.5.10) lib/ash/engine/engine.ex:556: Ash.Engine.fully_advance_request/2
       (ash 2.5.10) lib/ash/engine/engine.ex:497: Ash.Engine.do_run_iteration/2
       (elixir 1.14.2) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
       (ash 2.5.10) lib/ash/engine/engine.ex:440: Ash.Engine.run_iteration/1
       (ash 2.5.10) lib/ash/engine/engine.ex:257: Ash.Engine.run_to_completion/1
       (ash 2.5.10) lib/ash/engine/engine.ex:202: Ash.Engine.do_run/2
       (ash 2.5.10) lib/ash/engine/engine.ex:141: Ash.Engine.run/2
       (ash 2.5.10) lib/ash/actions/read.ex:170: Ash.Actions.Read.do_run/3
       (ash 2.5.10) lib/ash/actions/read.ex:90: Ash.Actions.Read.run/3
       (ash 2.5.10) lib/ash/api/api.ex:1005: Ash.Api.read_one/3
       (ash 2.5.10) lib/ash/api/api.ex:998: Ash.Api.read_one!/3
       test/aggregate_test.exs:44: (test)
2023-01-29 16:15:16 +10:00
Zach Daniel
3c496512e2 fix: use parent_expr instead of this
fix: various expression & type building fixes
2023-01-06 17:05:23 -05:00
Zach Daniel
01d1a8aa5d test: add test confirming embedded array behavior 2022-12-18 02:35:42 -05:00