-
Notifications
You must be signed in to change notification settings - Fork 2
fix: editing of FlagField via EnumFlagField form field #97
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
When attempting to edit an EnumFlagField through a model form (e.g. in django admin), the form would always be invalid on submit with an invalid_choice error. This was due to the form attempting to set the model field to a list of enum members (rather than bitwise-OR'ing the flags together). This change handles this case by overriding FlagField._coerce_to_value_type and performing the appropriate bitwise OR there.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #97 +/- ##
===========================================
- Coverage 100.00% 99.87% -0.13%
===========================================
Files 9 9
Lines 806 831 +25
Branches 117 123 +6
===========================================
+ Hits 806 830 +24
- Partials 0 1 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
bug confirmed #102 |
Thank you for the report and contribution @crgwbr! I'm going to move your _coerce_to_value_type implementation over to the form class. This is because we delegate all EnumField construction logic to the Enum's constructor. Custom construction logic may be implemented in |
Thanks for improving and merging this, @bckohan! Would you possibly be able to cut a patch release with this fix soon? Hoping to remove from my project the temporary monkey patch I used to workaround the bug. |
Yes, I'm hoping to get one out this weekend - a few other fixes are in progress wrt how the forms work by default. |
When attempting to edit an EnumFlagField through a model form (e.g. in django admin), the form would always be invalid on submit with an invalid_choice error. This was due to the form attempting to set the model field to a list of enum members (rather than bitwise-OR'ing the flags together).
This change handles this case by overriding FlagField._coerce_to_value_type and performing the appropriate bitwise OR there.