AF
Ash Framework•3mo ago
Ege

Sorting error: NoSuchField

Getting this error when trying to sort documents that have been uploaded by users:
(MatchError) no match of right hand side value: {:error, %Ash.Error.Invalid{errors: [%Ash.Error.Query.NoSuchField{resource: MyApp.Ash.Accounts.UserUpload, field: "uploaded_file_name", splode: Ash.Error, bread_crumbs: [], vars: [], path: [:sort], stacktrace: #Splode.Stacktrace<>, class: :invalid}]}}
(MatchError) no match of right hand side value: {:error, %Ash.Error.Invalid{errors: [%Ash.Error.Query.NoSuchField{resource: MyApp.Ash.Accounts.UserUpload, field: "uploaded_file_name", splode: Ash.Error, bread_crumbs: [], vars: [], path: [:sort], stacktrace: #Splode.Stacktrace<>, class: :invalid}]}}
Function that results in this error:
{:ok, %{results: documents, count: count}} =
UserUpload.by_ids(
%{organization_ids: org_ids},
query: [sort_input: "meta.uploaded_file_name"],
page: [limit: pagination.limit, offset: pagination.offset, count: true]
)
{:ok, %{results: documents, count: count}} =
UserUpload.by_ids(
%{organization_ids: org_ids},
query: [sort_input: "meta.uploaded_file_name"],
page: [limit: pagination.limit, offset: pagination.offset, count: true]
)
UserUpload resource:
attributes do
uuid_primary_key :id
attribute :document, :string, public?: true
attribute :meta, UserUploads.Meta, public?: true

create_timestamp :inserted_at
update_timestamp :updated_at
end
attributes do
uuid_primary_key :id
attribute :document, :string, public?: true
attribute :meta, UserUploads.Meta, public?: true

create_timestamp :inserted_at
update_timestamp :updated_at
end
UserUploads.Meta resource:
attributes do
attribute :uploaded_file_name, :string do
public? true
end
end
attributes do
attribute :uploaded_file_name, :string do
public? true
end
end
57 Replies
ZachDaniel
ZachDaniel•3mo ago
You can't sort on nested embedded fields that way currently I'd suggest making a calculation instead And sorting on that calculation Or use Ash.Expr.calc(meta.uploaded_file_name) instead of the string Make sure to require Ash.Expr first if you haven't
Ege
EgeOP•3mo ago
It's a bit strange that sorting on relationship fields works, but nested embedded fields does not Is this feature planned? You said "currently" I added this and it seems to work:
calculate :uploaded_file_name, :string, expr("meta.uploaded_file_name"), public?: true
calculate :uploaded_file_name, :string, expr("meta.uploaded_file_name"), public?: true
But I want to emphasize that having to treat these embedded fields as special just for sorting purposes adds technical debt. We have a lot of them. Never mind, the above expression doesn't really work, it just returns "meta.uploaded_file_name" as a string Also tried
calculate :uploaded_file_name, :string, expr(meta.uploaded_file_name), public?: true
calculate :uploaded_file_name, :string, expr(meta.uploaded_file_name), public?: true
ZachDaniel
ZachDaniel•3mo ago
calculate :uploaded_file_name, :string, expr(meta[:uploaded_file_name]), public?: true try that? calculate :uploaded_file_name, :string, expr(meta.uploaded_file_name), public?: true I thought that would work but if not then you may need to use brackets "Currently" is just that I'm open to supporting it I don't currently have plans to do it but issues & PRs welcome šŸ™‚
Ege
EgeOP•3mo ago
How do I sort by a timestamp field? I have create_timestamp :inserted_at, public?: true but trying to sort by that gives me NoSuchField error
no match of right hand side value: {:error, %Ash.Error.Invalid{errors: [%Ash.Error.Query.NoSuchField{resource: Myapp.Ash.Accounts.UserUpload, field: "inserted_at", splode: Ash.Error, bread_crumbs: [], vars: [], path: [:sort], stacktrace: #Splode.Stacktrace<>, class: :invalid}]}}
no match of right hand side value: {:error, %Ash.Error.Invalid{errors: [%Ash.Error.Query.NoSuchField{resource: Myapp.Ash.Accounts.UserUpload, field: "inserted_at", splode: Ash.Error, bread_crumbs: [], vars: [], path: [:sort], stacktrace: #Splode.Stacktrace<>, class: :invalid}]}}
ZachDaniel
ZachDaniel•3mo ago
šŸ¤” that should work What does Ash.Resource.Info.attribute(Resource, :inserted_at).public? show?
Ege
EgeOP•3mo ago
@Zach Daniel It shows true
ZachDaniel
ZachDaniel•3mo ago
šŸ¤” thats very strange. You definitely recompiled etc. after marking it as public?
Ege
EgeOP•3mo ago
it wouldn't show true if it was a compilation issue, right? I'm inside the iex that is also running the server.
ZachDaniel
ZachDaniel•3mo ago
not likely, no but it happens often and its worth restarting your server just in case šŸ¤·ā€ā™‚ļø easy thing to confirm Primarily because I don't see any reason you'd get that error otherwise
Ege
EgeOP•3mo ago
restarted the server, same issue
ZachDaniel
ZachDaniel•3mo ago
šŸ¤” Okay Can I see how you're calling it using that sort? Is it just this:
{:ok, %{results: documents, count: count}} =
UserUpload.by_ids(
%{organization_ids: org_ids},
query: [sort_input: "meta.uploaded_file_name"],
page: [limit: pagination.limit, offset: pagination.offset, count: true]
)
{:ok, %{results: documents, count: count}} =
UserUpload.by_ids(
%{organization_ids: org_ids},
query: [sort_input: "meta.uploaded_file_name"],
page: [limit: pagination.limit, offset: pagination.offset, count: true]
)
but with inserted_at?
Ege
EgeOP•3mo ago
{:ok, %{results: documents, count: count}} =
UserUpload.by_ids(
%{organization_ids: org_ids},
load: [:uploaded_file_name],
query: [sort_input: params.sort.sort_by],
page: [limit: pagination.limit, offset: pagination.offset, count: true]
)
{:ok, %{results: documents, count: count}} =
UserUpload.by_ids(
%{organization_ids: org_ids},
load: [:uploaded_file_name],
query: [sort_input: params.sort.sort_by],
page: [limit: pagination.limit, offset: pagination.offset, count: true]
)
Yes
ZachDaniel
ZachDaniel•3mo ago
Try hard coding it to :inserted_at as an atom? That shouldn't be it, but need to eliminate some possibilities šŸ˜„
Ege
EgeOP•3mo ago
Different error:
15:13:13.623 request_id=GFCuYpXdgocOKREAAHxB remote_ip=127.0.0.1 [error] ** (FunctionClauseError) no function clause matching in Ash.Sort.parse_input/3
(ash 3.5.11) lib/ash/sort/sort.ex:93: Ash.Sort.parse_input(MyApp.Ash.Accounts.UserUpload, :inserted_at, nil)
(ash 3.5.11) lib/ash/query/query.ex:559: Ash.Query.sort_input/3
(elixir 1.18.3) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
15:13:13.623 request_id=GFCuYpXdgocOKREAAHxB remote_ip=127.0.0.1 [error] ** (FunctionClauseError) no function clause matching in Ash.Sort.parse_input/3
(ash 3.5.11) lib/ash/sort/sort.ex:93: Ash.Sort.parse_input(MyApp.Ash.Accounts.UserUpload, :inserted_at, nil)
(ash 3.5.11) lib/ash/query/query.ex:559: Ash.Query.sort_input/3
(elixir 1.18.3) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
ZachDaniel
ZachDaniel•3mo ago
Right, updating Ash would fix that You should check if updating resolves the issue
Ege
EgeOP•3mo ago
We are on 3.5.11, what's the latest version?
ZachDaniel
ZachDaniel•3mo ago
mix hex.info ash
Ege
EgeOP•3mo ago
Great, I need to deal with the dependency hell be back in a bit
ZachDaniel
ZachDaniel•3mo ago
What is the dependency hell?
Ege
EgeOP•3mo ago
Resolving Hex dependencies...
Resolution completed in 0.101s
Because your app depends on ash ~> 3.5.26 which depends on igniter >= 0.6.4 and < 1.0.0-0, igniter >= 0.6.4 and < 1.0.0-0 is required.
So, because your app depends on igniter ~> 0.5.3, version solving failed.
Resolving Hex dependencies...
Resolution completed in 0.101s
Because your app depends on ash ~> 3.5.26 which depends on igniter >= 0.6.4 and < 1.0.0-0, igniter >= 0.6.4 and < 1.0.0-0 is required.
So, because your app depends on igniter ~> 0.5.3, version solving failed.
ZachDaniel
ZachDaniel•3mo ago
mix deps.update ash igniter Unless you've locked igniter to a specific version, then go change that to ~> 0.6
Ege
EgeOP•3mo ago
That didn't work. mix deps.update ash igniter upgraded these:
Upgraded:
finch 0.19.0 => 0.20.0 (minor)
plug 1.18.0 => 1.18.1
reactor 0.15.5 => 0.15.6
req 0.5.12 => 0.5.14
Upgraded:
finch 0.19.0 => 0.20.0 (minor)
plug 1.18.0 => 1.18.1
reactor 0.15.5 => 0.15.6
req 0.5.12 => 0.5.14
Afterwards, doing mix deps.get with ash version set to "3.5.26" results in the same error above.
ZachDaniel
ZachDaniel•3mo ago
Unless you've locked igniter to a specific version, then go change that to ~> 0.6
Ege
EgeOP•3mo ago
We don't have igniter defined in our mix.exs.
ZachDaniel
ZachDaniel•3mo ago
So, because your app depends on igniter ~> 0.5.3, version solving failed.
that says "your app" should mean that its in your own mix.exs
Ege
EgeOP•3mo ago
I found it in mix.lock
ZachDaniel
ZachDaniel•3mo ago
šŸ¤” it makes sense to be in mix.lock but still, that wouldn't say "your app" if it was from some dependency
Ege
EgeOP•3mo ago
I did mix deps.unlock igniter and that removed it from mix.lock at the top level, but it's still defined as a dependency of libraries like reactor and spark, as well as stuff like ash_phoenix. Not sure if that's the cause of the interference
ZachDaniel
ZachDaniel•3mo ago
There is no. other output from mix deps.update ash? Just that? And you are 100% sure it is not in your mix.exs file? Because all the other packages define it as an optional dependency meaning you should have no dependency on it at all if its not in your mix.exs
Ege
EgeOP•3mo ago
eersoz@macbookpro level % mix deps.update ash
Resolving Hex dependencies...
Resolution completed in 0.098s
Because your app depends on ash ~> 3.5.26 which depends on igniter >= 0.6.4 and < 1.0.0-0, igniter >= 0.6.4 and < 1.0.0-0 is required.
So, because your app depends on igniter ~> 0.5.3, version solving failed.
** (Mix) Hex dependency resolution failed
eersoz@macbookpro level % mix deps.update ash
Resolving Hex dependencies...
Resolution completed in 0.098s
Because your app depends on ash ~> 3.5.26 which depends on igniter >= 0.6.4 and < 1.0.0-0, igniter >= 0.6.4 and < 1.0.0-0 is required.
So, because your app depends on igniter ~> 0.5.3, version solving failed.
** (Mix) Hex dependency resolution failed
No description
ZachDaniel
ZachDaniel•3mo ago
:what: Are you using mishka?
Ege
EgeOP•3mo ago
I'm going to blow up mix lock and the deps folder
ZachDaniel
ZachDaniel•3mo ago
Something in your app has a non-optional dependency on igniter which is not typical
Ege
EgeOP•3mo ago
Claude doesn't think so
No description
ZachDaniel
ZachDaniel•3mo ago
feed it the output if mix deps.tree Anyway pretty strange Never seen that problem, and I have a bunch of apps that use all kinds of packages as well as igniter wait what does mix archive say? thats probably not it but worth checking
Ege
EgeOP•3mo ago
No description
Ege
EgeOP•3mo ago
the mystery deepens
ZachDaniel
ZachDaniel•3mo ago
mix deps.unlock igniter
Ege
EgeOP•3mo ago
already did that
ZachDaniel
ZachDaniel•3mo ago
And what about mix archive?
Ege
EgeOP•3mo ago
What do I do with that?
eersoz@macbookpro level % mix archive
* hex-2.1.1
Archives installed at: /Users/eersoz/.asdf/installs/elixir/1.18.3-otp-27/.mix/archives
eersoz@macbookpro level % mix archive
* hex-2.1.1
Archives installed at: /Users/eersoz/.asdf/installs/elixir/1.18.3-otp-27/.mix/archives
ZachDaniel
ZachDaniel•3mo ago
sometimes people accidentally add igniter as an archive
Ege
EgeOP•3mo ago
Anyway, let me deal with this offline. Doesn't seem like an Ash issue and I don't want to waste your time with it. Once I get Ash upgraded I'll come back
ZachDaniel
ZachDaniel•3mo ago
Something you could do is just add {:igniter, "~> 0.6", only: [:dev, :test], override: true} to potentially get around it since ideally we just want to find out if upgrading even fixes the sorting issue or not šŸ˜…
Ege
EgeOP•3mo ago
Adding that worked trying the sort now Ash is now on 3.5.26, according to mix.lock. Still getting this error:
15:44:47.839 request_id=GFCwG4E-IJ4Cc5wAAAPC remote_ip=127.0.0.1 [error] ** (FunctionClauseError) no function clause matching in Ash.Sort.parse_input/3
(ash 3.5.26) lib/ash/sort/sort.ex:93: Ash.Sort.parse_input(MyApp.Ash.Accounts.UserUpload, :inserted_at, nil)
(ash 3.5.26) lib/ash/query/query.ex:566: Ash.Query.sort_input/3
(elixir 1.18.3) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
15:44:47.839 request_id=GFCwG4E-IJ4Cc5wAAAPC remote_ip=127.0.0.1 [error] ** (FunctionClauseError) no function clause matching in Ash.Sort.parse_input/3
(ash 3.5.26) lib/ash/sort/sort.ex:93: Ash.Sort.parse_input(MyApp.Ash.Accounts.UserUpload, :inserted_at, nil)
(ash 3.5.26) lib/ash/query/query.ex:566: Ash.Query.sort_input/3
(elixir 1.18.3) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
Code:
{:ok, %{results: documents, count: count}} =
UserUpload.by_ids(
%{organization_ids: org_ids},
load: [:uploaded_file_name],
query: [sort_input: :inserted_at],
page: [limit: pagination.limit, offset: pagination.offset, count: true]
)
{:ok, %{results: documents, count: count}} =
UserUpload.by_ids(
%{organization_ids: org_ids},
load: [:uploaded_file_name],
query: [sort_input: :inserted_at],
page: [limit: pagination.limit, offset: pagination.offset, count: true]
)
ZachDaniel
ZachDaniel•3mo ago
😔 [sort_input: [:inserted_at]]
Ege
EgeOP•3mo ago
We are back to the original error:
15:54:35.662 request_id=GFCwpH26diqs1wAAAAkE remote_ip=127.0.0.1 [error] ** (MatchError) no match of right hand side value: {:error, %Ash.Error.Invalid{errors: [%Ash.Error.Query.NoSuchField{resource: MyApp.Ash.Accounts.UserUpload, field: :inserted_at, splode: Ash.Error, bread_crumbs: [], vars: [], path: [:sort], stacktrace: #Splode.Stacktrace<>, class: :invalid}]}}
15:54:35.662 request_id=GFCwpH26diqs1wAAAAkE remote_ip=127.0.0.1 [error] ** (MatchError) no match of right hand side value: {:error, %Ash.Error.Invalid{errors: [%Ash.Error.Query.NoSuchField{resource: MyApp.Ash.Accounts.UserUpload, field: :inserted_at, splode: Ash.Error, bread_crumbs: [], vars: [], path: [:sort], stacktrace: #Splode.Stacktrace<>, class: :invalid}]}}
ZachDaniel
ZachDaniel•3mo ago
Okay, can I see the attributes block of UserUpload? Just one final check before I say its a bug šŸ˜… I just want to be sure its all on the right resource etc. i.e my message before was just generic:
What does Ash.Resource.Info.attribute(Resource, :inserted_at).public? show?
so I haven't yet technically confirmed that you have :inserted_at on the right resource etc.
Ege
EgeOP•3mo ago
defmodule MyApp.Ash.Accounts.UserUpload do

attributes do
uuid_primary_key :id
attribute :document, :string, public?: true
attribute :meta, UserUploads.Meta, public?: true

create_timestamp :inserted_at, public?: false
update_timestamp :updated_at
end

end
defmodule MyApp.Ash.Accounts.UserUpload do

attributes do
uuid_primary_key :id
attribute :document, :string, public?: true
attribute :meta, UserUploads.Meta, public?: true

create_timestamp :inserted_at, public?: false
update_timestamp :updated_at
end

end
ZachDaniel
ZachDaniel•3mo ago
public?: false
Ege
EgeOP•3mo ago
I changed it earlier, let me change it back
ZachDaniel
ZachDaniel•3mo ago
should be public?: true
Ege
EgeOP•3mo ago
It works now. Looks like the upgrade fixed whatever the issue was. Also works with sort_input: "inserted_at" Do I need to make that a list like with [:inserted_at]?
ZachDaniel
ZachDaniel•3mo ago
So the only issue is when it is a single atom I will fix that
Ege
EgeOP•3mo ago
ok
ZachDaniel
ZachDaniel•3mo ago
You should figure out how to remove that igniter override
Ege
EgeOP•3mo ago
Yeah

Did you find this page helpful?