Re: [Django] #23222: Empty BinaryField != b'' on Python 2

2016-12-29 Thread Django
#23222: Empty BinaryField != b'' on Python 2
-+-
 Reporter:  wkschwartz@… |Owner:  Grzegorz
 |  Ślusarek
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  wontfix
 Keywords:  py2  | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Tim Graham):

 * status:  assigned => closed
 * resolution:   => wontfix


Comment:

 Closing due to the end of Python 2 support in master in a couple weeks.

--
Ticket URL: 
Django 
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 post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/078.f66f580f23a5f328e6cf68b7bd945720%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #23222: Empty BinaryField != b'' on Python 2

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

 * keywords:   => py2


--
Ticket URL: 
Django 
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 post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/078.a9c30cf349f613004e59da7f4cc84199%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #23222: Empty BinaryField != b'' on Python 2

2015-03-17 Thread Django
#23222: Empty BinaryField != b'' on Python 2
-+-
 Reporter:  wkschwartz@… |Owner:  gregorth
 Type:  Bug  |   Status:  assigned
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
-+-
Description changed by wkschwartz:

Old description:

> = Problem =
>
> In Python 2, at least under SQLite, the initial value for an empty binary
> field behaves inconsistently. The ORM thinks it's an empty `bytes`:
> `b''`. The database connection manager thinks it's a buffer. Now, the
> buffer evaluates to `False` and has zero length. So it'll mostly work.
> But not always -- and most importantly to me, not in my unit tests!
>
> See http://stackoverflow.com/q/12625557/1286628
>
> Note this was not a problem under Python 3.4.
>
> = Steps to Reproduce =
>
> Using Python 2.7.8, SQLite, and either Django 1.7rc2 or Django @
> edcc75e5ac5b9dc2f174580e7adacd3be586f8bd (HEAD at the time of this
> writing; the error exists in both places)
>
> 1. Make a new project and a new app and add the app to settings.py
> 2. Fill in `app/models.py` as follows
>
> {{{#!python
> from django.db import models
> class BinModel(models.Model):
> data = models.BinaryField()
> }}}
>
> 3. Run from the command line:
>
> {{{#!bash
> (venv) $ ./manage.py makemigrations app ./manage.py migrate &&
> ./manage.py shell
> }}}
>
> 4. Run from the resulting Python shell
>
> {{{#!python
> >>> from app import models; m = models.BinModel(); m.save(); n =
> models.BinModel.objects.get()
> >>> m.data
> ''
> >>> m.data == b''
> True
> >>> n.data
> 
> >>> n.data == b''
> False
> >>> bool(n.data)
> False
> >>> len(n.data)
> 0
> >>> bytes(n.data)
> ''
> }}}
>
> Note that the same problem persisted when I had a default value for the
> field. There was no problem under Python 3.4.

New description:

 = Problem =

 In Python 2, at least under SQLite, the initial value for an empty binary
 field behaves inconsistently. The ORM thinks it's an empty `bytes`: `b''`.
 The database connection manager thinks it's a buffer. Now, the buffer
 evaluates to `False` and has zero length. So it'll mostly work. But not
 always -- and most importantly to me, not in my unit tests!

 See http://stackoverflow.com/q/12625557/1286628

 Note this was not a problem under Python 3.4.

 = Steps to Reproduce =

 Using Python 2.7.8, SQLite, and either Django 1.7rc2 or Django @
 edcc75e5ac5b9dc2f174580e7adacd3be586f8bd (HEAD at the time of this
 writing; the error exists in both places)

 1. Make a new project and a new app and add the app to settings.py
 2. Fill in `app/models.py` as follows

 {{{#!python
 from django.db import models
 class BinModel(models.Model):
 data = models.BinaryField()
 }}}

 3. Run from the command line:

 {{{#!bash
 (venv) $ ./manage.py makemigrations app && ./manage.py migrate &&
 ./manage.py shell
 }}}

 4. Run from the resulting Python shell

 {{{#!python
 >>> from app import models; m = models.BinModel(); m.save(); n =
 models.BinModel.objects.get()
 >>> m.data
 ''
 >>> m.data == b''
 True
 >>> n.data
 
 >>> n.data == b''
 False
 >>> bool(n.data)
 False
 >>> len(n.data)
 0
 >>> bytes(n.data)
 ''
 }}}

 Note that the same problem persisted when I had a default value for the
 field. There was no problem under Python 3.4.

--

--
Ticket URL: 
Django 
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 post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/078.2c67af687337e2bed596b843ca22b343%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #23222: Empty BinaryField != b'' on Python 2

2015-03-17 Thread Django
#23222: Empty BinaryField != b'' on Python 2
-+-
 Reporter:  wkschwartz@… |Owner:  gregorth
 Type:  Bug  |   Status:  assigned
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
-+-
Changes (by gregorth):

 * status:  new => assigned
 * owner:  nobody => gregorth


--
Ticket URL: 
Django 
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 post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/078.a8098e4e4fd00cf322a66a018ed1a048%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #23222: Empty BinaryField != b'' on Python 2

2015-01-15 Thread Django
#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: 
Django 
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 post to this group, send email to django-updates@googlegroups.com.
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.


Re: [Django] #23222: Empty BinaryField != b'' on Python 2

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

 * stage:  Unreviewed => Accepted


Comment:

 Marking this as accepted per previous comments.

 This seem like it might be caused by six using buffers on python 2 [1].

 Thanks.

 [1] https://github.com/django/django/blob/master/django/utils/six.py#L681

-- 
Ticket URL: 
Django 
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 post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/078.0106b39d387b5a88d7f2171d50f234b0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #23222: Empty BinaryField != b'' on Python 2 (was: Empty BinaryField != b'' in Python 2/SQLite)

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

-- 
Ticket URL: 
Django 
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 post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/078.c0fa9d8a785712a9f3b1e51c8d1f25d3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.