Sorting error: NoSuchField
Getting this error when trying to sort documents that have been uploaded by users:
Function that results in this error:
UserUpload resource:
UserUploads.Meta resource:
57 Replies
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'tIt'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:
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
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 š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
š¤ that should work
What does
Ash.Resource.Info.attribute(Resource, :inserted_at).public?
show?@Zach Daniel It shows
true
š¤ thats very strange. You definitely recompiled etc. after marking it as public?
it wouldn't show
true
if it was a compilation issue, right? I'm inside the iex that is also running the server.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
restarted the server, same issue
š¤ Okay
Can I see how you're calling it using that sort?
Is it just this:
but with
inserted_at
?
Yes
Try hard coding it to
:inserted_at
as an atom? That shouldn't be it, but need to eliminate some possibilities šDifferent error:
Right, updating Ash would fix that
You should check if updating resolves the issue
We are on 3.5.11, what's the latest version?
mix hex.info ash
Great, I need to deal with the dependency hell
be back in a bit
What is the dependency hell?
mix deps.update ash igniter
Unless you've locked igniter to a specific version, then go change that to ~> 0.6
That didn't work.
mix deps.update ash igniter
upgraded these:
Afterwards, doing mix deps.get
with ash version set to "3.5.26" results in the same error above.Unless you've locked igniter to a specific version, then go change that to ~> 0.6
We don't have igniter defined in our mix.exs.
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
I found it in mix.lock
š¤
it makes sense to be in mix.lock
but still, that wouldn't say "your app" if it was from some dependency
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 interferenceThere 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

:what:
Are you using mishka?
I'm going to blow up mix lock and the deps folder
Something in your app has a non-optional dependency on igniter which is not typical
Claude doesn't think so

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
the mystery deepens
mix deps.unlock igniter
already did that
And what about
mix archive
?What do I do with that?
sometimes people accidentally add igniter as an archive
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
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 š
Adding that worked
trying the sort now
Ash is now on 3.5.26, according to mix.lock. Still getting this error:
Code:
š”
[sort_input: [:inserted_at]]
We are back to the original error:
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.public?: false
I changed it earlier, let me change it back
should be
public?: true
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]
?So the only issue is when it is a single
atom
I will fix thatok
You should figure out how to remove that igniter override
Yeah