#30774: Migrations uses value of enum object instead of its name.
-------------------------------------+-------------------------------------
     Reporter:  oasl                 |                    Owner:  Hasan
                                     |  Ramezani
         Type:  Bug                  |                   Status:  assigned
    Component:  Migrations           |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  Enum, Migrations     |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Hasan Ramezani):

 Here is the diff based on the **@oasl** solution

 {{{
 Shouldn't the code generated by the migration uses the name of the Status
 Enum 'GOOD', not the value of it, since it is changeable?
 It should be:
 ('status', models.CharField(default=Status['GOOD'], max_length=128))
 }}}


 {{{
 diff --git a/django/db/migrations/serializer.py
 b/django/db/migrations/serializer.py
 index 27b5cbd379..b00c6f0df2 100644
 --- a/django/db/migrations/serializer.py
 +++ b/django/db/migrations/serializer.py
 @@ -120,9 +120,9 @@ class EnumSerializer(BaseSerializer):
      def serialize(self):
          enum_class = self.value.__class__
          module = enum_class.__module__
 -        v_string, v_imports =
 serializer_factory(self.value.value).serialize()
 +        _, v_imports = serializer_factory(self.value.value).serialize()
          imports = {'import %s' % module, *v_imports}
 -        return "%s.%s(%s)" % (module, enum_class.__name__, v_string),
 imports
 +        return "%s.%s['%s']" % (module, enum_class.__name__, self.value),
 imports


 }}}

 @felixxm, what do you think?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30774#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/062.74b345c21f5cbf1e31cec2b902c66768%40djangoproject.com.

Reply via email to