inline `type()` doesnt work. when defined as calculation on resource it works.

i have a really weird issue and i have no idea whats happening:
# this works, where `:id_as_string` is the calculation: expr(type(:id, :string))
authorize_if expr(^actor([:service, :id_as_string]) in addressed_groups)

# this doesnt work:
authorize_if expr(type(^actor([:service, :id]), :string) in addressed_groups)
# this works, where `:id_as_string` is the calculation: expr(type(:id, :string))
authorize_if expr(^actor([:service, :id_as_string]) in addressed_groups)

# this doesnt work:
authorize_if expr(type(^actor([:service, :id]), :string) in addressed_groups)
addressed_groups is an {:array, :string} type. If I try to do the type casting inline, second example I get this error:
Invalid Error

* Invalid filter value `246` supplied in `#Ecto.Query<from w0 in ExEbau.Workflow.WorkItem, as: 0, where: not is_nil(
type(
as(0).deadline,
{:parameterized,
{Ash.Type.DateTime.EctoType,
precision: :second, cast_dates_as: :start_of_day, timezone: :utc}}
)
), where: type(^246, {:parameterized, {AshPostgres.Type.StringWrapper.EctoType, []}}) in type(
as(0).addressed_groups,
{:array, {:parameterized, {AshPostgres.Type.StringWrapper.EctoType, []}}}
), select: struct(w0, [
Invalid Error

* Invalid filter value `246` supplied in `#Ecto.Query<from w0 in ExEbau.Workflow.WorkItem, as: 0, where: not is_nil(
type(
as(0).deadline,
{:parameterized,
{Ash.Type.DateTime.EctoType,
precision: :second, cast_dates_as: :start_of_day, timezone: :utc}}
)
), where: type(^246, {:parameterized, {AshPostgres.Type.StringWrapper.EctoType, []}}) in type(
as(0).addressed_groups,
{:array, {:parameterized, {AshPostgres.Type.StringWrapper.EctoType, []}}}
), select: struct(w0, [
41 Replies
ZachDaniel
ZachDanielβ€’4mo ago
Hmm....thats strange. I did some type work recently might be worth checking on latest versions just in case
Stephan
StephanOPβ€’4mo ago
{:ash, git: "https://github.com/ash-project/ash.git", branch: "main", override: true},
ZachDaniel
ZachDanielβ€’4mo ago
I don't think it will fix this though
Stephan
StephanOPβ€’4mo ago
im on main
ZachDaniel
ZachDanielβ€’4mo ago
πŸ‘ was worth a shot πŸ˜†
Stephan
StephanOPβ€’4mo ago
im always on main for all my ash dependencies lol
ZachDaniel
ZachDanielβ€’4mo ago
πŸ˜† I feel like the last month may have been a weird ride for you then
Stephan
StephanOPβ€’4mo ago
#yolo
barnabasj
barnabasjβ€’4mo ago
well being on main doesn't mean you update every day necessarily though
ZachDaniel
ZachDanielβ€’4mo ago
right πŸ˜† πŸ€¦β€β™‚οΈ
Stephan
StephanOPβ€’4mo ago
No description
Stephan
StephanOPβ€’4mo ago
3 days ago
ZachDaniel
ZachDanielβ€’4mo ago
So, I'm not sure why the calculation works
Stephan
StephanOPβ€’4mo ago
the calculation is literally just this:
calculations do
calculate :id_as_string, :string, expr(type(id, :string))
end
calculations do
calculate :id_as_string, :string, expr(type(id, :string))
end
ZachDaniel
ZachDanielβ€’4mo ago
Isn't that different? ^actor([:service, :id]),
Stephan
StephanOPβ€’4mo ago
@barnabasj you wrote smokestack right? how come its not namespaced under the ash namespace?
ZachDaniel
ZachDanielβ€’4mo ago
It was @jart
Stephan
StephanOPβ€’4mo ago
ah sry
ZachDaniel
ZachDanielβ€’4mo ago
Its his personal project πŸ˜„
Stephan
StephanOPβ€’4mo ago
thats because the check is a policy somewhere else
policies do
policy action_type(:read) do
# this works, where `:id_as_string` is the calculation: expr(type(:id, :string))
# authorize_if expr(^actor([:service, :id_as_string]) in addressed_groups)

# this doesnt work:
authorize_if expr(type(^actor([:service, :id]), :string) in addressed_groups)

# is this a bug?
end
end
policies do
policy action_type(:read) do
# this works, where `:id_as_string` is the calculation: expr(type(:id, :string))
# authorize_if expr(^actor([:service, :id_as_string]) in addressed_groups)

# this doesnt work:
authorize_if expr(type(^actor([:service, :id]), :string) in addressed_groups)

# is this a bug?
end
end
ZachDaniel
ZachDanielβ€’4mo ago
smokestack is licensed differently than Ash etc. you should read the license if you want to use it.
Stephan
StephanOPβ€’4mo ago
ah yh saw that. im mainly writing software for building permits in switzerland so i should be good to go and its open source
ZachDaniel
ZachDanielβ€’4mo ago
πŸ”₯
Stephan
StephanOPβ€’4mo ago
gonna train fixing ash to 3.5.15
ZachDaniel
ZachDanielβ€’4mo ago
I have a random thought of something that might work looking at some of the changes we've made we can improve those string wrapper types
barnabasj
barnabasjβ€’4mo ago
Switzerland, nice. You shouldn't be to far from me then. I live at the swiss border
Stephan
StephanOPβ€’4mo ago
du bisch vo ΓΆstrich gell? so 3.5.15 does the same thing
* Invalid filter value `252` supplied in `#Ecto.Query<from w0 in ExEbau.Workflow.WorkItem, as: 0, where: not is_nil(
type(
as(0).deadline,
{:parameterized,
{Ash.Type.DateTime.EctoType,
precision: :second, cast_dates_as: :start_of_day, timezone: :utc}}
)
), where: type(
type(^252, {:parameterized, {AshPostgres.Type.StringWrapper.EctoType, []}}),
{:parameterized, {AshPostgres.Type.StringWrapper.EctoType, []}}
) in type(
as(0).addressed_groups,
{:array, {:parameterized, {AshPostgres.Type.StringWrapper.EctoType, []}}}
), select: struct(w0, [
:id,
:meta,
:status,
:deadline,
:created_at,
:assigned_users,
:addressed_groups,
:task_id,
:controlling_groups,
:case_id
])>`
* Invalid filter value `252` supplied in `#Ecto.Query<from w0 in ExEbau.Workflow.WorkItem, as: 0, where: not is_nil(
type(
as(0).deadline,
{:parameterized,
{Ash.Type.DateTime.EctoType,
precision: :second, cast_dates_as: :start_of_day, timezone: :utc}}
)
), where: type(
type(^252, {:parameterized, {AshPostgres.Type.StringWrapper.EctoType, []}}),
{:parameterized, {AshPostgres.Type.StringWrapper.EctoType, []}}
) in type(
as(0).addressed_groups,
{:array, {:parameterized, {AshPostgres.Type.StringWrapper.EctoType, []}}}
), select: struct(w0, [
:id,
:meta,
:status,
:deadline,
:created_at,
:assigned_users,
:addressed_groups,
:task_id,
:controlling_groups,
:case_id
])>`
ZachDaniel
ZachDanielβ€’4mo ago
I just pushed something to main of ash_postgres I will probably have no effect but it can't hurt to try πŸ˜„
Stephan
StephanOPβ€’4mo ago
let me try yh didnt make a difference do you want me to try and build a failing test?
ZachDaniel
ZachDanielβ€’4mo ago
very much so ❀️
Stephan
StephanOPβ€’4mo ago
ok let me try
ZachDaniel
ZachDanielβ€’4mo ago
I made a similar "probably won't help" change in main
Stephan
StephanOPβ€’4mo ago
i cant reproduce it.. ah maybe in a read action wait
ZachDaniel
ZachDanielβ€’4mo ago
are you also on main for ash_sql?
Stephan
StephanOPβ€’4mo ago
got it i think
test/type_test.exs:104
** (Ash.Error.Invalid)
Bread Crumbs:
> Error returned from: AshPostgres.Test.Post.with_version_check

Invalid Error

* Invalid filter value `1` supplied in `#Ecto.Query<from p0 in AshPostgres.Test.Post, as: 0, where: type(as(0).type, {:parameterized, {Ash.Type.Atom.EctoType, unsafe_to_atom?: false}}) ==
type(^"sponsored", {:parameterized, {Ash.Type.Atom.EctoType, []}}), where: type(
type(
^1,
{:parameterized, {AshPostgres.Type.StringWrapper.EctoType, allow_empty?: true, trim?: false}}
),
{:parameterized, {AshPostgres.Type.StringWrapper.EctoType, allow_empty?: true, trim?: false}}
) in ["1", "2"], select: struct(p0, [
:organization_id,
:point,
:price,
:author_id,
:string_point,
:uniq_on_upper,
test/type_test.exs:104
** (Ash.Error.Invalid)
Bread Crumbs:
> Error returned from: AshPostgres.Test.Post.with_version_check

Invalid Error

* Invalid filter value `1` supplied in `#Ecto.Query<from p0 in AshPostgres.Test.Post, as: 0, where: type(as(0).type, {:parameterized, {Ash.Type.Atom.EctoType, unsafe_to_atom?: false}}) ==
type(^"sponsored", {:parameterized, {Ash.Type.Atom.EctoType, []}}), where: type(
type(
^1,
{:parameterized, {AshPostgres.Type.StringWrapper.EctoType, allow_empty?: true, trim?: false}}
),
{:parameterized, {AshPostgres.Type.StringWrapper.EctoType, allow_empty?: true, trim?: false}}
) in ["1", "2"], select: struct(p0, [
:organization_id,
:point,
:price,
:author_id,
:string_point,
:uniq_on_upper,
read :with_version_check do
argument :version, :integer

filter expr(type(^arg(:version), :string) in ["1", "2"])
end
read :with_version_check do
argument :version, :integer

filter expr(type(^arg(:version), :string) in ["1", "2"])
end
this fails when being called with Ash.Query.for_read(Post, :with_version_check, [version: 1]) it works when not explicitely casting the int to string:
read :with_version_check do
argument :version, :integer

# filter expr(type(^arg(:version), :string) in ["1", "2"])
filter expr(^arg(:version) in ["1", "2"])
end
read :with_version_check do
argument :version, :integer

# filter expr(type(^arg(:version), :string) in ["1", "2"])
filter expr(^arg(:version) in ["1", "2"])
end
ZachDaniel
ZachDanielβ€’4mo ago
strange well, make a PR and I'll get to it this week if you don't mind
Stephan
StephanOPβ€’4mo ago
πŸ’―
ZachDaniel
ZachDanielβ€’4mo ago
Not mega high priority since you have a workaround but still a weird one worth fixing
Stephan
StephanOPβ€’4mo ago
yh its weird..
Stephan
StephanOPβ€’4mo ago
GitHub
fix: add failing test for type() in expression by StephanH90 Β· P...
This commit currently only adds a failing test. Contributor checklist Leave anything that you believe does not apply unchecked. Bug fixes include regression tests Chores Documentation changes ...
Stephan
StephanOPβ€’4mo ago
but @Zach Daniel ... you said you will fix it next week! its only sunday ah it was just an ash_sql bump

Did you find this page helpful?