Opened 5 years ago

Closed 5 years ago

#26140 closed Cleanup/optimization (fixed)

BinaryField value must be declared "binary" in queries to avoid MySQL 5.7+ warning

Reported by: Tim Graham Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: giovanni@…, guilhem.bichot@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

There are a couple warnings with running the Django test suite on MySQL 5.7:

test_json_serializer (serializers.test_data.SerializerDataTests) ... /media/sf_django/django/db/backends/mysql/base.py:112: Warning: Invalid utf8 character string: 'FD00'
  return self.cursor.execute(query, args)

test_set_and_retrieve (model_fields.tests.BinaryFieldTests) ... /media/sf_django/django/db/backends/mysql/base.py:112: Warning: Invalid utf8 character string: 'FE'

I think these are both fixed by changing our queries from something like

cursor.execute("""
    INSERT INTO `field` (binary)
    VALUES (%s)
""", data)

to:

cursor.execute("""
    INSERT INTO `field` (binary)
    VALUES (_binary %s)
""", data)

The "_binary" tells MySQL that the following string is to be interpreted as binary, not to be interpreted/validated as utf8.
http://dev.mysql.com/doc/refman/5.7/en/charset-literal.html

There's some background in #26139.

Change History (7)

comment:1 Changed 5 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted

comment:2 Changed 5 years ago by Giovanni Go

Cc: giovanni@… added

comment:3 Changed 5 years ago by Guilhem Bichot

Cc: guilhem.bichot@… added

comment:4 Changed 5 years ago by Claude Paroz

comment:5 Changed 5 years ago by Claude Paroz

Has patch: set

comment:6 Changed 5 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:7 Changed 5 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In 204e00c0:

Fixed #26140 -- Suppressed MySQL warning when inserting binary content

Thanks Tim Graham for the review.

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