These are chat archives for django/django

24th
Aug 2016
Adole Samuel
@int-elligentSam
Aug 24 2016 00:48
Cheers everyone
Is there a way to loop through two iterables using one for loop statement in DTL?
Adole Samuel
@int-elligentSam
Aug 24 2016 00:54
In normal python I use the zip() function but I don't think there's one like that in DTL, or is there?
Andrew Backer
@awbacker
Aug 24 2016 09:45
Hi, i 'm converting a project from 2 to 3, and am getting a crash in set_attributes_from_name during ./manage.py test saying that a bytes-like object is required. I can't find where it could be coming from, and the admin seems to work ok in general.
  File "venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 664, in set_attributes_from_name
    self.verbose_name = self.name.replace('_', ' ')
Andrew Backer
@awbacker
Aug 24 2016 09:58
  • actually, also happens in migrate
Andrew Backer
@awbacker
Aug 24 2016 10:37

Found it by doing this:

python -m pdb ./manage.py migration <app> 0001  # sure something else would have worked too
> enter `c` at debugger to continue
> self.name  # print out the name causing issues.  easy enough to find after that

Error was a migration containing a field name prefixed by b for some reason when no others did.

Andrew Backer
@awbacker
Aug 24 2016 12:01
On a maybe related note, my JSONFields suddenly started returning str where before they worked perfectly. <wth>.
w._meta.fields includes <django.contrib.postgres.fields.jsonb.JSONField: data>, but calling w.data => '{"name":"sam"}' and not a dict. In 2.7 it was ok :-/
Andrew Backer
@awbacker
Aug 24 2016 12:24
Any idea on what might have gone wrong, or if we somehow did something accidentally that made it work before?
Igor Malinov
@malinich
Aug 24 2016 12:27
w.to_python() ???
are you use django same version?
Andrew Backer
@awbacker
Aug 24 2016 12:28
or json.loads(), yes. but not sure what changed. Install in a 3.5 venv and it's a str, installed in a 2.7 venv before and its a dict
Uzayr
@uzayr
Aug 24 2016 12:28
pymysql not working mf
Andrew Backer
@awbacker
Aug 24 2016 12:28
yup, only changed what was required for py3 compatbility, like iteritems and octal numbers, and upgraded a dependency.
oh, crap.. yeah, django 1.9.7, postgres 9.5
Andrew Backer
@awbacker
Aug 24 2016 13:18
um? advertisement?
Andrew Backer
@awbacker
Aug 24 2016 13:27
@malinich As to your to_python comment... we have django-jsonfield installed before, but a custom fork. I replaced that with the pypi one since it only exists in migrations now. However... whatever it was doing, it seems to have been somehow still used. even though the model instance says it is jsonb.JSONField, it is somehow still decoding to a dict
Andrew Backer
@awbacker
Aug 24 2016 13:34
holy MO#()$#)$(@FU#(#$ER
found it... in django-jsonfield it *globally disables psycopg json parsing
def configure_database_connection(connection, **kwargs):
    if connection.vendor != 'postgresql':
        return
    # Ensure that psycopg does not do JSON decoding under the hood
    # We want to be able to do our own decoding with our own options
    import psycopg2.extras
    if hasattr(psycopg2.extras, 'register_default_jsonb'):
        psycopg2.extras.register_default_jsonb(connection.connection,globally=False,loads=lambda x: x)
Adole Samuel
@int-elligentSam
Aug 24 2016 23:21
@mkzia thanks, exactly what I was looking for