Opened 8 years ago

Closed 8 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: dev
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 by Claude Paroz, 8 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Giovanni Go, 8 years ago

Cc: giovanni@… added

comment:3 by Guilhem Bichot, 8 years ago

Cc: guilhem.bichot@… added

comment:4 by Claude Paroz, 8 years ago

comment:5 by Claude Paroz, 8 years ago

Has patch: set

comment:6 by Tim Graham, 8 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Claude Paroz <claude@…>, 8 years ago

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