Skip to content

Fix dropping readonly fields from change#1780

Merged
Flo0807 merged 2 commits intonaymspace:developfrom
kepi:fix/drop-readonly-fields
Mar 27, 2026
Merged

Fix dropping readonly fields from change#1780
Flo0807 merged 2 commits intonaymspace:developfrom
kepi:fix/drop-readonly-fields

Conversation

@kepi
Copy link
Copy Markdown
Contributor

@kepi kepi commented Jan 28, 2026

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_changes function directly to tests, just so I can test if it works.

But I think better (not ideal) way would be making the drop_readonly_changes non-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.

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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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/3 in Backpex.FormComponent to 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.

@Flo0807 Flo0807 added the bug Something isn't working label Mar 27, 2026
@Flo0807 Flo0807 self-assigned this Mar 27, 2026
@Flo0807 Flo0807 requested a review from Copilot March 27, 2026 11:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@Flo0807 Flo0807 added this pull request to the merge queue Mar 27, 2026
@Flo0807 Flo0807 changed the title Fix dropping readonly fields from Change Fix dropping readonly fields from change Mar 27, 2026
@Flo0807
Copy link
Copy Markdown
Collaborator

Flo0807 commented Mar 27, 2026

But I think better (not ideal) way would be making the drop_readonly_changes non-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.

I moved the function to Backpex.Field and made it public.

Merged via the queue into naymspace:develop with commit cb891ea Mar 27, 2026
11 checks passed
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

Successfully merging this pull request may close these issues.

3 participants