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

 * status:  closed => new
 * resolution:  needsinfo =>


Comment:

 To experience the bug:

 In any Django project, set the default value of a CharField as an enum
 object:

 {{{
 class EnumClass(Enum):
      VALUE = _('Value')
 }}}
 where:
 VALUE: is the constant enum object name
 'Value': is the translatable enum object value

 In the model:
 {{{
 field = models.CharField(default=EnumClass.VALUE, max_length=128)
  }}}

 then run: python manage.py makemigrations

 In the generated migration file, you will notice that the default value of
 the field is set to: EnumClass('Value'), so it calls the enum object by
 its value not it is constant name.
 run: python manage.py migrate

 In the settings.py file:
 {{{
 LANGUAGE_CODE = 'fr-FR' # set it to any language code other than English
 }}}

 Run the project after generating, translating, and compiling the messages
 file (see: [https://docs.djangoproject.com/en/2.2/topics/i18n/translation
 /#message-files message-files])

 The project will raise the error: {{{ ValueError: 'Value' is not a valid
 EnumClass }}}, on the generated migration file.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30774#comment:3>
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.567aef412e55c6c4470901d79546fa42%40djangoproject.com.

Reply via email to