#23222: Empty BinaryField != b'' on Python 2
-------------------------------------+-------------------------------------
     Reporter:  wkschwartz@…         |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by raully7):

 I'm not sure, if it's only a problem with empty Empty BinaryField.

 I try to add a test function in model_fields.tests.BinaryFieldTests, as
 below:

 {{{
     def test_retrieve_compare_non_empty_field(self):
         dm = DataModel(data=b'test')
         self.assertTrue(dm.data == b'test')
         dm.save()
         dm = DataModel.objects.get(pk=dm.pk)
         self.assertTrue(dm.data == b'test')
 }}}

 On python2, the first assertion will be passed, and the second one will be
 failed.

 As the data field is a buffer type after retrieving, we can't do a simple
 compare.

 We can see the definition:

 {{{
 class BinaryField(Field):
     ...
     def get_db_prep_value(self, value, connection, prepared=False):
         value = super(BinaryField, self).get_db_prep_value(value,
 connection, prepared)
         if value is not None:
             return connection.Database.Binary(value)
         return value
 }}}

 I can't go further as I know little about six, and hope this can help:)

--
Ticket URL: <https://code.djangoproject.com/ticket/23222#comment:5>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/078.7f099b9a31f4d75ba7d2321d68747a7d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to