Skip to content
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

handle enum type for nested ChoiceFields #400

Merged
merged 1 commit into from Jul 15, 2019

Conversation

etene
Copy link
Contributor

@etene etene commented Jul 4, 2019

Hello,

On a project I'm working on, I'm using Django IntegerFields, with a choices parameter, nested in postgres ArrayFields. This translates to a ListField with a child ChoiceField in the ModelSerializer.

The issue I'm having is that ChoiceFieldInspector fails to properly infer the resulting enum type, even though it could because it can guess it correctly for IntegerFields:

  • First, it tries to get the corresponding model field, but since the nested ChoiceField has no source, it fails. I fixed it by using parent.source.
  • Then, even if it manages to get the corresponding model field, it's an ArrayField so get_basic_type_info doesn't return anything. I fixed it by using the base_field if present.

This PR adds some code that fixes the issue & a test. Feel free to tell me if I solved the problem the wrong way; tests seem to pass so I don't think I broke anything.

@axnsan12
Copy link
Owner

Seems good, thank you!

@axnsan12 axnsan12 merged commit 6417bb3 into axnsan12:master Jul 15, 2019
@etene etene deleted the nested-choice-fields branch July 15, 2019 16:08
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.

None yet

2 participants