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

Nested enum generates incorrect migration #30

Open
wli opened this issue Dec 30, 2015 · 4 comments
Open

Nested enum generates incorrect migration #30

wli opened this issue Dec 30, 2015 · 4 comments

Comments

@wli
Copy link

wli commented Dec 30, 2015

This is using Django 1.9 with django-enumfield 1.3b2

class Hike(models.Model):
    class ExposureType(enum.Enum):
        UNKNOWN = 0
    exposure_type = enum.EnumField(ExposureType, default=ExposureType.UNKNOWN)

generates

    operations = [
        migrations.AlterField(
            model_name='hike',
            name='exposure_type',
            field=django_enumfield.db.fields.EnumField(default=0, enum=base.models.ExposureType),
        ),

It should instead generate enum=base.models.Hike.ExposureType

@andreif
Copy link
Contributor

andreif commented Feb 10, 2017

Interesting, I would normally keep all enums away from heavy modules, so one can import them without moving montains. We'll look if we can support this. Thanks for reporting the issue and sorry for late reply!

@hyusetiawan
Copy link

I am having the same issue as well, rather annoying
@andreif I see your point about moving mountains, for smaller models though, it's more maintainable to have enum that only applies to this particular model. Makes it more neatly scoped :)

@antonagestam
Copy link
Contributor

I think this bug should be accepted and fixed. The increased coherence of defining enums inside models should be encouraged.

I believe this might be fixed by replacing __name__ with __qualname__, but that isn't available in Python 2.7 and early versions of 3.x. Now that Python 2.7 is EOL, we should probably discuss ending backwards compatibility for some of those versions anyway.

@cyberpion-yotam
Copy link

Any news on this?

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

5 participants