Fix dropping readonly fields from change#1780
Conversation
When experimenting with AshBackpex, I found out that :readonly fields aren't correctly dropped from a Change. As I have :update action which accepts only some of fields, I need this working. Only alternative would be to omit read only fields from edit form which doesn't suit my use case. I also added simple tests for this, but as there is currently no LiveView test infrastructure, I used dirty workaround and copied private drop_readonly_changes function directly to tests for now so I can see if it works.
There was a problem hiding this comment.
Pull request overview
Fixes a bug where :readonly fields were not being removed from form params before building a changeset, which matters for adapters/actions that only accept a subset of fields (e.g., Ash update actions).
Changes:
- Correct
drop_readonly_changes/3inBackpex.FormComponentto handle the actual{name, options}field tuple structure. - Add ExUnit coverage around readonly evaluation and readonly-field param dropping behavior (currently via a mirrored helper).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
lib/backpex/live_components/form_component.ex |
Fixes readonly filtering by passing field options (not the full tuple) into Backpex.Field.readonly?/2. |
test/field_test.exs |
Adds tests for Backpex.Field.readonly?/2 and intended readonly param dropping behavior (but currently tests a local copy of the logic). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
I moved the function to |
When experimenting with AshBackpex, I found out that :readonly fields aren't correctly dropped from a Change.
As I have :update action which accepts only some of fields, I need this working. Only alternative would be to omit read only fields from edit form which doesn't suit my use case.
I also added simple tests for this, but I don't really know how to test this correctly with existing tests structure. For now, I used dirty workaround and copied private
drop_readonly_changesfunction directly to tests, just so I can test if it works.But I think better (not ideal) way would be making the
drop_readonly_changesnon-private and add@doc false. Are you OK with that? Ideal would be probably to setup some "infrastructure" for LiveView and check whole process, but I'm not even sure where to begin with that.