Opened 7 years ago

Closed 7 years ago

#6960 closed (fixed)

PositiveSmallInteger comes with unicode value from admin

Reported by: kmmbvnr@… Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords: type error nfa-fixed
Cc: Triage Stage: Fixed on a branch
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If i save this model from admin, the type_x field comes as unicode.
When getting existing instances, the type_x field have int type.

Choices = (                                                                     
    (1,u'a'),                                                                   
    (2,u'b')                                                                    
)                                                                               
                                                                                
class Test(models.Model):                                                       
    type_x  = models.PositiveSmallIntegerField(choices=Choices,default=1)       
                                                                                
    def save(self):                                                             
        assert isinstance(self.type_x, int)                                     
        super(Test,self).save(self)                                             
                                                                                
    class Admin:                                                                
        pass    

Change History (3)

comment:1 Changed 7 years ago by Karen Tracey <kmtracey@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Fixed on a branch

I suspect this has the same root cause as #6853. For some reason when the old manipulator code creates a new object for a field with choices set, the field value is not an integer type but rather the unicode representation of the integer. This is not a problem on newforms-admin.

comment:2 Changed 7 years ago by Karen Tracey <kmtracey@…>

  • Keywords nfa-fixed added

comment:3 Changed 7 years ago by brosner

  • Resolution set to fixed
  • Status changed from new to closed

This is no longer a problem since the merge of newforms-admin in [7967].

Note: See TracTickets for help on using tickets.
Back to Top