Skip to content

Conversation

@DGollings
Copy link
Contributor

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

Otherwise as discussed @zachdaniel (I presume)

@DGollings DGollings force-pushed the main branch 3 times, most recently from ce86c98 to fa4f2cb Compare October 28, 2025 16:05
@zachdaniel
Copy link
Contributor

I believe the last thing we want to do is make sure that this key is cleared from any resulting record's metadata.

@DGollings
Copy link
Contributor Author

I believe the last thing we want to do is make sure that this key is cleared from any resulting record's metadata.

done plus test

@zachdaniel
Copy link
Contributor

We're close! Thank you so much for bearing with me on this one.

@DGollings DGollings force-pushed the main branch 3 times, most recently from e0018e2 to c2136df Compare October 31, 2025 15:15
@DGollings
Copy link
Contributor Author

DGollings commented Oct 31, 2025

We're close! Thank you so much for bearing with me on this one.

Appreciate (and understand) the thorough review :)
Resolved your comments in c2136df

Updated and also opened ash-project/ash_postgres#645 and ash-project/ash_sqlite#189 (the latter needs some work tests should pass, but because I do not use ash_sqlite its harder to thoroughly test)

It passes my repro test, please review
(I'll check the failing CI jobs asap)

|> Ash.Changeset.prepare_changeset_for_action(action, opts)
|> Ash.Changeset.set_private_arguments_for_action(opts[:private_arguments] || %{})
|> Ash.Changeset.put_context(context_key, %{index: index})
|> Ash.Changeset.put_context(:bulk_update, %{index: index, ref: ref})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to use the context_key variable here and make sure we aren't hardcoding it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, changed to

-    |> Ash.Changeset.put_context(:bulk_update, %{index: index, ref: ref})
+    |> Ash.Changeset.put_context(context_key, %{index: index, ref: ref})

:destroy ->
{:bulk_destroy, :bulk_destroy_index}
end
context_key = :bulk_update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to switch on action.type so that this uses the action type for these three values. For destroys the context key, metadata key, and ref_metadata_key need to be based on the action type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one I was less sure about, but I think you mean:

-    context_key = :bulk_update
-    metadata_key = :bulk_update_index
-    ref_metadata_key = :bulk_action_ref
+    {context_key, metadata_key, ref_metadata_key} =
+      case action.type do
+        :destroy ->
+          {:bulk_destroy, :bulk_destroy_index, :bulk_action_ref}
+
+        _ ->
+          {:bulk_update, :bulk_update_index, :bulk_action_ref}
+      end

Correct?

removed unnecessary find_changeset_by_index
@DGollings
Copy link
Contributor Author

Updated @zachdaniel , all tests (still) pass (although now I'm wondering if we need an extra test or two?)

if ref_metadata_key do
ref_key = result.__metadata__[ref_metadata_key]

changesets_by_ref
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't need this check.

@zachdaniel
Copy link
Contributor

Feel bad that I keep doing a drive by on this PR and finding small things.

With the existing data layers currently returning indexes, I'm pretty sure this needs to handle that properly. i.e if we get back a record with a bulk index but not a ref, we should look up the ref by index in a map of index -> ref. Someday down the line we can undo that call. This could be tested at least in the interim by having the ETS data layer only return an index and seeing how it breaks.

@DGollings
Copy link
Contributor Author

DGollings commented Nov 6, 2025

And here I am impressed by your restraint, not simply making the necessary changes yourself and merging it in :)

I intentionally had zero backwards compatibility, but makes sense to have some, added in ea31926c so it can be cleanly reverted in the future

@DGollings DGollings force-pushed the main branch 2 times, most recently from dd93e8c to e437c5c Compare November 8, 2025 10:48
@zachdaniel zachdaniel merged commit 36706c5 into ash-project:main Nov 9, 2025
45 checks passed
@zachdaniel
Copy link
Contributor

🚀 Thank you for your contribution! 🚀

@DGollings
Copy link
Contributor Author

thought we'd never get this merged 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants