Skip to content

list of enums no longer works after upgrade to 4.x #615

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
vincentschut opened this issue Mar 20, 2025 · 1 comment
Open

list of enums no longer works after upgrade to 4.x #615

vincentschut opened this issue Mar 20, 2025 · 1 comment

Comments

@vincentschut
Copy link

vincentschut commented Mar 20, 2025

We have some constance items that are lists of enums.
We defined these with a custom type like this:

CONSTANCE_CONFIG = {
...
'CHORD_CDM_PLATFORMS':
        ([], 'platforms to preprocess and use for deforestation', 'platform_select'),
...
}

And

CONSTANCE_ADDITIONAL_FIELDS = {
    'platform_select': ['dprof.fields.MultipleChoiceSelect', {
        'enum': 'dprof.models.scene.Platform',
        'widget': 'django.forms.CheckboxSelectMultiple',
        'required': False,
    }],
...
}

MultipleChoiceSelect is a custom subclass of django's MultipleChoiceField, and overrides the to_python(...) and prepare_value(...) methods, to convert from a list of ints (or strings of ints) to a list of enums, and vice versa.

In constance 3.x, this worked without problem. If I accessed config.CHORD_CDM_PLATFORMS I got a list of Platform enums back.

In constance 4.x, if I access config.CHORD_CDM_PLATFORMS, I get a list of integers, which further in the code leads to all kinds of errors, because the usual properties that this enum has (e.g. .values, .names) do not exist.

I tried registering a new custom type (like in codecs.py), but I could not figure out how to link that to our 'platform_select' field. Whatever I do, constance puts a "default" value as the "discriminator" string in the database, so the new type was never linked to our 'platform_select' type.

Is there a way to make sure that this works again?
To me the most obvious way would be to "fix" constance so that it calls <custom_field>.to_python(...) on config value access, and <custom_field>.prepare_value(...) when setting a config value. But maybe that won't work, or another way is better?

I really hope a solution is somehow possible.

Thanks!
Vincent.

@vincentschut
Copy link
Author

Gentle ping :-)

I hope someone more knowledgeable than me about constance development is reading this?

If there is no hope to work together towards a solution for this, please let me know. No hard feelings, but we will then have to look for an alternative to Constance, because this is currently holding back the upgrade and that is sooner or later going to bite us.

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

No branches or pull requests

1 participant