Skip to content

Fixes #19092: scope type selection lost when editing multiple/all objects #19102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025

Conversation

jnovinger
Copy link
Member

@jnovinger jnovinger commented Apr 7, 2025

Fixes: #19092

This essentially reverts the previous fix for #18964, which attempted to fix the issue with some objects not being updated when the "select all s matching query" checkbox was marked by restoring an else clause that had been removed in the fix for #18194. However, doing so regressed the fix for #18194 while still leaving most of the changes for that fix in place.

Rather than trying to guess all of the possible fields that might need to be stuffed in to initial_data across all bulk edit view/form combinations, I took the approach of making a copy of request.POST and over-writing the pk list with what ever we determined to use earlier in the BulkEditView.post() method. With this approach, anything that is set in the form is still transmitted to the form instance via request.POST but the pk list set in initial_data is instead overridden by the expected value. The end result is that all users selections on the form, as well as the object selections to edit, are preserved for the next iteration of the form.

@jnovinger jnovinger requested review from a team and jeremystretch and removed request for a team April 7, 2025 19:21
form = self.form(request.POST, initial=initial_data)
post_data = request.POST.copy()
post_data.setlist('pk', pk_list)
form = self.form(post_data, initial=initial_data)
Copy link
Member Author

Choose a reason for hiding this comment

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

I think you could argue that pk_list no longer needs to be set in initial_data anymore.

Copy link
Member

Choose a reason for hiding this comment

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

Let's leave it for now as there are a few scattered instances of it being referenced (in InterfaceBulkEditForm, for instance), perhaps incorrectly.

@jnovinger jnovinger changed the title Fixes #19092: scope type selection lost when editing multiple/all obj… Fixes #19092: scope type selection lost when editing multiple/all objects Apr 7, 2025
Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

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

I want to say there was a reason we avoided binding POST data to the form on the initial request, but I can't recall what it was or whether it would still be a concern. It doesn't appear to break anything AFAICT.

form = self.form(request.POST, initial=initial_data)
post_data = request.POST.copy()
post_data.setlist('pk', pk_list)
form = self.form(post_data, initial=initial_data)
Copy link
Member

Choose a reason for hiding this comment

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

Let's leave it for now as there are a few scattered instances of it being referenced (in InterfaceBulkEditForm, for instance), perhaps incorrectly.

@jeremystretch jeremystretch merged commit 3020854 into main Apr 9, 2025
6 checks passed
@jeremystretch jeremystretch deleted the 19092-bulk-edit-loses-scope-type-choice branch April 9, 2025 18:55
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression: Bulk Edit fails to update Scope when using ContentTypeChoiceField (HTMX)
2 participants