Does Api.bulk_create support action's arguments?

I'm try to create items that are related to the workspace by using bulk_create
create :create do
primary? true
accept [:start, :result]

argument :workspace_id, :uuid do
allow_nil? false
end

change manage_relationship(:workspace_id, :workspace, type: :append_and_remove)
end
create :create do
primary? true
accept [:start, :result]

argument :workspace_id, :uuid do
allow_nil? false
end

change manage_relationship(:workspace_id, :workspace, type: :append_and_remove)
end
but I don't know how to pass workspace_id as an argument
6 Replies
ZachDaniel
ZachDaniel2y ago
Yep! You stream a set of action inputs into the bulk create call How are you calling it now?
Bananoid
BananoidOP2y ago
Api.bulk_create(
[
%{workspace_id: "1e4657e7...", start: 0, result: %{...}},
%{workspace_id: "1e4657e7...", start: 0, result: %{...}},
...
], ItemResource, :create)
Api.bulk_create(
[
%{workspace_id: "1e4657e7...", start: 0, result: %{...}},
%{workspace_id: "1e4657e7...", start: 0, result: %{...}},
...
], ItemResource, :create)
but I get an error
%Ash.BulkResult{
status: :error,
errors: [],
records: nil,
notifications: [],
error_count: 3
}
%Ash.BulkResult{
status: :error,
errors: [],
records: nil,
notifications: [],
error_count: 3
}
I'm not providing a stream but a list of maps
ZachDaniel
ZachDaniel2y ago
Add the return_errors?: true option
Bananoid
BananoidOP2y ago
%Ash.BulkResult{
status: :error,
errors: [
%Ash.Error.Invalid{
errors: [
%Ash.Error.Changes.Required{
field: :workspace_id,
type: :argument,
resource: Resources.Transcription,
changeset: nil,
query: nil,
error_context: [],
vars: [],
path: [],
stacktrace: #Stacktrace<>,
class: :invalid
}
],
stacktraces?: true,
changeset: nil,
query: nil,
error_context: [],
vars: [],
path: [],
stacktrace: #Stacktrace<>,
class: :invalid
} |
nil
],
records: nil,
notifications: [],
error_count: 1
}
%Ash.BulkResult{
status: :error,
errors: [
%Ash.Error.Invalid{
errors: [
%Ash.Error.Changes.Required{
field: :workspace_id,
type: :argument,
resource: Resources.Transcription,
changeset: nil,
query: nil,
error_context: [],
vars: [],
path: [],
stacktrace: #Stacktrace<>,
class: :invalid
}
],
stacktraces?: true,
changeset: nil,
query: nil,
error_context: [],
vars: [],
path: [],
stacktrace: #Stacktrace<>,
class: :invalid
} |
nil
],
records: nil,
notifications: [],
error_count: 1
}
I think that the problem could be that workspace_id is an action arguments and not a resource attribute?
ZachDaniel
ZachDaniel2y ago
Hmm…it should support action arguments… Try this?
[
%{workspace_id: "1e4657e7...", start: 0, result: %{...}},
%{workspace_id: "1e4657e7...", start: 0, result: %{...}},
...
]
|> Stream.map(&Ash.Changeset.for_update(ItemResource, &1, :create)
|> Api.bulk_create(ItemResource, :create)
[
%{workspace_id: "1e4657e7...", start: 0, result: %{...}},
%{workspace_id: "1e4657e7...", start: 0, result: %{...}},
...
]
|> Stream.map(&Ash.Changeset.for_update(ItemResource, &1, :create)
|> Api.bulk_create(ItemResource, :create)
nah, that won't work So, the next steps are 1. make sure that all of your inputs definitely have workspace_id set 2. open an issue on ash and I'll take a look this afternoon I just added a test that shows that bulk create can be used with arguments oh
%Ash.Error.Changes.Required{
field: :workspace_id,
type: :argument,
resource: Resources.Transcription,
changeset: nil,
query: nil,
error_context: [],
vars: [],
path: [],
stacktrace: #Stacktrace<>,
class: :invalid
}
%Ash.Error.Changes.Required{
field: :workspace_id,
type: :argument,
resource: Resources.Transcription,
changeset: nil,
query: nil,
error_context: [],
vars: [],
path: [],
stacktrace: #Stacktrace<>,
class: :invalid
}
The resource there is Resources.Transcription So I think maybe you're creating something else and no supplying workspace_id?
Bananoid
BananoidOP2y ago
hey sorry it work. Was just a typo 😵‍💫

Did you find this page helpful?