Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assumption failed: got a query without a domain #1649

Open
sevenseacat opened this issue Dec 10, 2024 · 3 comments
Open

Assumption failed: got a query without a domain #1649

sevenseacat opened this issue Dec 10, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@sevenseacat
Copy link
Contributor

Describe the bug

I'm probably doing something a bit weird, but I wanted to see if calculations on embedded resources somehow had access to their parent resource.

(I find myself wanting something like this fairly often, or eg. loading one calculation on a top level resource and passing data from the result down through relationships to be stored on the children)

So I whipped up this:

defmodule MyApp.Dispatch.EmailRecipient do
  use Ash.Resource, data_layer: :embedded

  # lots of other code 

  calculations do
    calculate :foo, :string, fn one, two ->
      dbg()
      "foo"
    end
  end
end

This resource is embedded in a Payload resource (which is a union, but I don't think that matters), which is then embedded in a Notification resource.

So I loaded a Notification and went into it to get the EmailRecipient:

iex(1)> n = Ash.get!(MyApp.Dispatch.Notification, "0043864d-15be-4ce2-876c-57d0171d2fd8")
#MyApp.Dispatch.Notification<...>
iex(3)> r = hd(n.payload.value.recipients)
#MyApp.Dispatch.EmailRecipient<
  foo: #Ash.NotLoaded<:calculation, field: :foo>,
  ...
>

And then tried to load the foo calculation:

iex(4)> Ash.load(r, :foo)
** (Ash.Error.Framework.AssumptionFailed) Assumption failed: got a query without a domain

This should not be possible, please report a detailed bug at:

https://github.com/ash-project/ash/issues/new?assignees=&labels=bug%2C+needs+review&template=bug_report.md&title=

    (ash 3.4.38) lib/ash/actions/read/read.ex:41: Ash.Actions.Read.run/3
    (ash 3.4.38) lib/ash.ex:1858: Ash.load/3
    (ash 3.4.38) lib/ash.ex:1812: Ash.load/3
    iex:4: (file)

Using reuse_values?: true also raises the same error.

It tells me to report a bug, so here I am!

Expected behavior

I'd get the debug printout of whatever the calculation sees, to answer my question if somehow it knows about where its embedded in (I suspect the answer is no, but still). And the calculation would successfully calculate the value "foo".

Runtime

  • Elixir version 1.16.3-otp-26
  • Erlang version 26.2.5.1
  • OS macOS Sonoma
  • Ash version 3.4.38
@sevenseacat sevenseacat added bug Something isn't working needs review labels Dec 10, 2024
@zachdaniel
Copy link
Contributor

Hmmm... you could try configurIng a domain on the embedded resource, or specifying the domain option to Ash.load. If we can't determine a domain then we can't do any action logic, so we probably just need a better error message there?

@sevenseacat
Copy link
Contributor Author

I've not actually used embedded resources before, so if they're not supposed to be used like this, that's fine! This issue is here for posterity if other people try to do it and wonder why it doesn't work :)

I'll give those options a go in the morning - but I don't think a domain should be specified on an embedded resource, should it? Or can you embed a resource cross-domain?

@zachdaniel
Copy link
Contributor

zachdaniel commented Dec 10, 2024

We may actually prevent specifying a domain on an embedded resource now that I think of it. The idea is that since they are meant to be used as a type, their domain would always be inherited from whichever resource contains them.

I forget, you may have to try it out to confirm. But I do think specifying the domain option ought to be supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants