Skip to content

Fixes: #17794 - Setup get_field_value to return multiple values when required #19188

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DanSheps
Copy link
Member

Fixes: #17794 - Setup get_field_value to return multiple values in the event of multi-values passed in a modelmultiplechoice or multiplechoice field.

  • Edit tests
  • Edit get_field_value to return multiple values in the event of a Multi-Value field being passed

@DanSheps DanSheps self-assigned this Apr 15, 2025
@DanSheps DanSheps requested review from a team and jeremystretch and removed request for a team April 28, 2025 13:08
@DanSheps DanSheps marked this pull request as ready for review April 28, 2025 13:08
@DanSheps
Copy link
Member Author

A note, I could rewrite this to use a new function, get_field_values() in the case of form fields with MultipleChoice fields. This seemed like the path of least resistance.

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 wasn't able to reproduce the original issue. Could you please update #17794 with complete reproduction steps?

@DanSheps
Copy link
Member Author

Yeah, I can do that, however, it isn't really something reproducable without editing our code.

The reason for this, after diving into it, is this was originally blocking #17211 as I originally wanted to do:

        tagged_vlans = get_field_value(self, 'tagged_vlans') if 'tagged_vlans' in self.fields.keys() else []

in the clean() on dcim/forms/common.py (line 46) however to not have it blocked, we instead did:

        if 'tagged_vlans' in self.fields.keys():
            tagged_vlans = self.cleaned_data.get('tagged_vlans') if self.is_bound else \
                self.get_initial_for_field(self.fields['tagged_vlans'], 'tagged_vlans')
        else:
            tagged_vlans = []

This would still help as it would clean up this logic slightly I suppose but I think this could also be closed out if we deem it not required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Utility function get_field_value returns last value when used on a multi-value field
2 participants