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
8eabbde953
add tests for new transaction behavior
2023-02-10 15:41:41 -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
80cd06818d
improvement: optimized first
aggregates where possible
2023-02-08 14:46:29 -05:00
Zach Daniel
8d45e92fc2
fix: do limit/offset outside of query if distinct is required
2023-02-07 19:15:44 -05:00
Zach Daniel
b41d383b47
fix: load by __order__ ascending
2023-02-07 17:43:53 -05:00
Alan Heywood
09092cc051
test: demonstrate issue loading aggregate
...
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 when
loading the aggregate as part of the query.
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: %{}, calculations: %{}, data_layer: AshPostgres.DataLayer, public?: false, relationship_path: [], resource: AshPostgres.Test.Comment, root_resource: AshPostgres.Test.Comment}
Context Relationship Path: []
At Path: []
Path: [:organization, :users]
Related: nil
Expression: exists(organization.users, [id: "df84db36-b8de-485b-8e47-a86307588f79"])
code: |> Api.load!(:count_of_comments, actor: user)
stacktrace:
(ash 2.5.13) lib/ash/filter/filter.ex:2121: Ash.Filter.add_expression_part/3
(ash 2.5.13) 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.13) lib/ash/filter/filter.ex:295: Ash.Filter.parse/5
(ash 2.5.13) lib/ash/query/query.ex:1803: Ash.Query.do_filter/2
(elixir 1.14.2) lib/map.ex:883: Map.update!/3
(ash 2.5.13) lib/ash/engine/request.ex:654: Ash.Engine.Request.apply_filter/4
(ash 2.5.13) lib/ash/engine/request.ex:561: Ash.Engine.Request.do_strict_check/3
(ash 2.5.13) lib/ash/engine/request.ex:522: 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.13) lib/ash/engine/request.ex:255: Ash.Engine.Request.do_next/1
(ash 2.5.13) lib/ash/engine/request.ex:211: Ash.Engine.Request.next/1
(ash 2.5.13) lib/ash/engine/engine.ex:650: Ash.Engine.advance_request/2
(ash 2.5.13) lib/ash/engine/engine.ex:556: Ash.Engine.fully_advance_request/2
(ash 2.5.13) 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.13) lib/ash/engine/engine.ex:440: Ash.Engine.run_iteration/1
(ash 2.5.13) lib/ash/engine/engine.ex:257: Ash.Engine.run_to_completion/1
(ash 2.5.13) lib/ash/engine/engine.ex:202: Ash.Engine.do_run/2
(ash 2.5.13) lib/ash/engine/engine.ex:141: Ash.Engine.run/2
(ash 2.5.13) lib/ash/actions/read.ex:170: Ash.Actions.Read.do_run/3
(ash 2.5.13) lib/ash/actions/read.ex:90: Ash.Actions.Read.run/3
(ash 2.5.13) lib/ash/api/api.ex:928: Ash.Api.load/4
(ash 2.5.13) lib/ash/api/api.ex:902: Ash.Api.load!/4
test/aggregate_test.exs:48: (test)
2023-01-31 10:35:33 +10: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
acc947292d
Add failing test for inserting via Ecto.Repo.insert!
...
It should be possible to use this function, and it did work as of ash
v2.5.9. This test fails as of ash v2.5.10, which introduced adding
relationships to underlying ecto schemas. The bug is related to a
has_many relationship being present on the resource.
The test fails with:
1) test call Ecto.Repo.insert! via Ash Repo (AshPostgres.EctoCompatibilityTest)
test/ecto_compatibility_test.exs:6
** (Ecto.InvalidChangesetError) could not perform insert because changeset is invalid.
Errors
%{posts: [{"is invalid", [type: {:array, :map}]}]}
Applied changes
%{name: "The Org"}
Params
nil
Changeset
#Ecto.Changeset<
action: :insert,
changes: %{name: "The Org"},
errors: [posts: {"is invalid", [type: {:array, :map}]}],
data: #AshPostgres.Test.Organization<>,
valid?: false
>
code: |> AshPostgres.TestRepo.insert!()
stacktrace:
(ecto 3.9.4) lib/ecto/repo/schema.ex:270: Ecto.Repo.Schema.insert!/4
test/ecto_compatibility_test.exs:9: (test)
2023-01-30 10:40:45 +10:00
Zach Daniel
04a64b8b94
chore: credo
2023-01-29 18:24:11 -05: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
e81e77840a
fix: don't group aggregates that reference relationships in their filters
2022-12-21 16:58:12 -05:00
Zach Daniel
09b19c8bfd
improvement: add like and ilike
2022-12-21 16:12:49 -05:00
Zach Daniel
01d1a8aa5d
test: add test confirming embedded array behavior
2022-12-18 02:35:42 -05:00
Zach Daniel
a5b1bc8a3f
fix: properly add aggregates to query when referenced from calculations
...
fixes : #127
2022-12-18 02:23:39 -05:00
Alan Heywood
df3b4fd82c
Add a failing test to repro a bug with calculation loads
2022-12-17 22:57:25 +10:00
Zach Daniel
bfefef7fd5
improvement: distinct on source of query, not relationship destination
2022-12-15 17:16:53 -05:00
Zach Daniel
5987515b8d
fix: properly combine sort + to many join filter
2022-12-14 22:37:10 -05:00
Zach Daniel
9d6996be25
fix: make migration generator work better for umbrellas
2022-12-13 13:31:57 -05:00
Zach Daniel
68c6d7aaf8
improvement: better error messages from mix tasks
...
fix: various broken behavior from new aggregate work
improvement: validate that references refer to relationships
closes #99
2022-12-10 15:59:50 -05:00
Zach Daniel
e271a27d3c
improvement: avg/min/max/custom aggregate support
...
fix: fix various problems with the model behind aggregates
2022-12-07 20:32:38 -05:00
Zach Daniel
7d0663588f
chore: add test with join in many to many
2022-12-04 13:39:58 -05:00
Zach Daniel
52fcba79ac
improvement: inform users about postgres incompatibility with multidimensional arrays
2022-12-01 20:24:49 -05:00
Darren Black
f088601cf9
Failing tests for aggregates on arrays ( #121 )
2022-11-30 21:26:58 -05:00
Zach Daniel
f03332c13b
chore: fix tests
2022-11-30 20:59:18 -05:00
Zach Daniel
498d54e812
improvement: update ash, add test for transaction hooks
2022-11-30 20:51:06 -05:00
Zach Daniel
059837651d
improvement: add unique constraints to changeset for custom unique indexes
...
improvement: separate out concurrent index creations and do them in a separate transaction
2022-11-25 14:06:22 -05:00
Zach Daniel
b4efb3a343
test: fix tests for migration_defaults
2022-11-21 02:45:09 -05:00
Zach Daniel
8f064db2f0
chore: work on tests for migration_defaults
2022-11-21 02:39:57 -05:00
Zach Daniel
2451879d46
test: add test for code interface
2022-10-31 11:53:03 -04:00
Zach Daniel
dbfca0ec57
chore: format
2022-10-24 22:17:42 -06:00
Kyle Grinstead
a88687c1d5
fix: && operator in expressions to point to ash_elixir_and ( #115 )
2022-10-24 22:13:12 -06:00
Zach Daniel
13413d3cc7
feat: support now()
in latest Ash
2022-10-20 01:08:35 -04:00
Zach Daniel
5222e1e755
improvement: handle UUID types better
2022-10-17 08:40:32 -05:00
Zach Daniel
fb8a13f33d
improvement: set lateral join source for latest ash
...
improvement: use `prepend?: true` option when applying relationship sorts
2022-10-15 00:03:16 -05:00
Zach Daniel
a8b44fef0f
fix: no unnecessary type cast on count/sum aggregates
2022-10-10 12:12:17 -04:00
Zach Daniel
7fd1e73baa
fix: don't apply filter
to array_agg
2022-10-10 12:06:54 -04:00
Zach Daniel
94edf64322
fix: use attribute source for identity fields
2022-10-04 16:13:52 -04:00
Zach Daniel
fd5ac60072
improvement: exists
filters necessitate multiple aggregate joins (for now)
2022-09-28 18:01:20 -04:00
Zach Daniel
6ad57501ff
improvement: upgrade to new exists
usage
2022-09-25 14:41:29 -04:00
Zach Daniel
e8643d4aa0
fix: properly type cast top level fragments
...
chore: update tests not to use deprecated helper
2022-09-21 13:36:18 -04:00
Zach Daniel
31d0ec20ac
improvement: support latest ash
2022-09-20 23:00:29 -04:00
Darren Black
b0292d66f8
improvement: implement Length function ( #111 )
2022-09-15 16:51:49 -04:00
Zach Daniel
11561ea163
improvement: support latest ash
2022-09-14 12:59:01 -04:00
Zach Daniel
7fc6c91cac
improvement: support manual relationships with joins
2022-09-13 16:40:12 -04:00
Zach Daniel
79879e0bd6
fix: keep unique index keys in order in migrations
...
closes #109
2022-09-10 01:41:25 -04:00