Repository navigation
Conversation
The hidden inputs of the HasManyThrough pivot rows and the "used elsewhere" message of the delete item action each depend on a package Backpex uses nowhere else. These tests pin both behaviours before the packages are dropped.
Backpex used each package once: phoenix_html_helpers for the hidden inputs of the HasManyThrough pivot rows, postgrex for the struct of a foreign key violation in the delete item action. The inputs are plain HEEx now and the error is matched as a map, so apps no longer get both packages through Backpex.
Flo0807
force-pushed
the
refactor/drop-one-use-deps
branch
from
November 11, 2026 17:08
1c60d38 to
28b189a
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
Backpex forced two packages on every app and used each of them in one place:
phoenix_html_helpers:lib/backpex/fields/has_many_through.eximportedPhoenixHTMLHelpers.Form.hidden_inputs_for/1for the hidden inputs (the pivot record's primary key) in the edit modal of each pivot row.postgrex:lib/backpex/item_actions/delete.exmatched%Postgrex.Error{postgres: %{code: :foreign_key_violation}}in two heads oferror_message/3to add "The item is used elsewhere." / "The items are used elsewhere." to the flash.What changed
Backpex.Fields.HasManyThroughrenders the hidden inputs with a plain HEEx loop overe.hidden, withPhoenix.HTML.Form.input_id/2andinput_name/2. The markup is the same as before:<input id="parent_pivots_0_id" name="parent[pivots][0][id]" type="hidden" value="11">.phoenix_html_helpersis removed frommix.exs,mix.lockanddemo/mix.lock(the demo only had it through Backpex).Backpex.ItemActions.Deletematches the error as%{__struct__: Postgrex.Error, postgres: %{code: :foreign_key_violation}}, which needs no loaded module, andpostgrexisoptional: true. The lock files keeppostgrex: Backpex's own project still fetches an optional dependency, and the demo lists it itself.guides/upgrading/v0.25.md(apps listpostgrexthemselves, andphoenix_html_helpersif their own code calls it), and the installation guide names PostgreSQL andpostgrexin the prerequisites.Label
breaking-change: an app that got one of the packages only through Backpex has to list it now.How it was tested
The first commit only adds tests that pin the behaviour. They pass with
lib/,mix.exsandmix.lockofdevelop(16 passed in the three files) and with the change:test/fields/has_many_through_test.exs: "renders the hidden inputs of each pivot row" compares the hidden inputs as written in the HTML, for two existing pivot rows and a new one.integration_test/fields/has_many_through_test.exs: "keeps its pivot record when the form is saved" saves the edit form of a user with an address and checks that the pivot record keeps its id.integration_test/item_actions/delete_test.exs: "an item that other records reference" deletes addresses that a user references, one from the show view and two selected on the index, and checks both flash messages. There was no test for these messages before. The adapter deletes withRepo.delete_all/1, so this is thePostgrex.Errorpath.Both HasManyThrough tests fail when the loop renders no inputs (checked by replacing
e.hiddenwith[]).Commands (all exit 0):
MIX_ENV=test mix lint:2335 mods/funs, found no issues.,1367 passed (167 doctests, 1200 tests), 60 excludedmix deps.unlock --check-unusedmix docs --warnings-as-errorsmix gettext.extract --check-up-to-dateINTEGRATION_TESTS=false mix test:1041 passed (167 doctests, 874 tests)postgrexline removed frommix.exsin a separate build path,INTEGRATION_TESTS=false mix compile --force --warnings-as-errorsandINTEGRATION_TESTS=false mix testpassed (1041 passed), andCode.ensure_loaded?(Postgrex.Error)wasfalsewhileBackpex.ItemActions.Deleteloaded.demo/:mix deps.unlock --check-unusedfailed with:phoenix_html_helpersbeforemix deps.unlock --unusedand passes after it.Surfaces
:edit(HasManyThrough modal), item actionDeleteon:showand:index(bulk).Backpex.Fields.HasManyThroughonly;BelongsTo,HasManyandInlineCRUDdon't use the helper.backpex.potis up to date.AddressLiveandUserLivefixtures cover the new tests.usage-rules.mdandplugin/skills/don't mention the two packages.For the reviewer
hidden_inputs_for/1also handled list values (name[], indexed ids). The loop does not: the form of a pivot row comes from the changeset, wherehiddenholds the primary key fields of the pivot schema. A pivot schema with an array-typed primary key would render differently; I did not test that case.demo/mix.lockwas updated withmix deps.unlock --unusedon the host, not in the demo container. The demo was not compiled or started, andbun run lintof the demo did not run.demo/lib/demo_web/item_actions/user_soft_delete.exstill matches%Postgrex.Error{}, which works because the demo listspostgrexitself.