Add a new MySQL backend for safely working with BinaryFields.

Review Request #8636 — Created Jan. 19, 2017 and submitted

Information

Djblets
release-0.9.x
1ad04a8...

Reviewers

Django 1.6 introduced a BinaryField type for storing binary content.
This is useful, except that, depending on database settings, MySQL will
perform a UTF8 validation check on the binary content being saved to the
database. This is clearly not what we want. Newer versions of Django
(1.10.5+) fix this by declaring the content to be binary, using the
"_binary" identifier when inserting/updating, but older versions are out
of luck.

This change introduces a new MySQL database backend that adds this
support for older versions of Django. When activated (by setting the
backend in settings.py), binary content will safely get the _binary
prefix.

This backend will also allow us to eventually tweak things in the
database so that we can add better defaults (encodings and otherwise)
for databases.

Switched Review Board to use this backend for MySQL. Verified that
I was able to import all the binary data that was in my old database
without getting an error (which I was receiving before).

Description From Last Updated

"If" should be capitalized.

daviddavid

These should be bytestrings, no?

daviddavid

Bytestring?

daviddavid
reviewbot
  1. Tool: PEP8 Style Checker
    Processed Files:
        djblets/db/backends/mysql/base.py
    
    Ignored Files:
        djblets/db/backends/__init__.py
        djblets/db/backends/mysql/__init__.py
    
    
    
    Tool: Pyflakes
    Processed Files:
        djblets/db/backends/mysql/base.py
    
    Ignored Files:
        djblets/db/backends/__init__.py
        djblets/db/backends/mysql/__init__.py
    
    
  2. 
      
david
  1. 
      
  2. djblets/db/backends/mysql/base.py (Diff revision 1)
     
     
    Show all issues

    "If" should be capitalized.

  3. djblets/db/backends/mysql/base.py (Diff revision 1)
     
     
     
     
    Show all issues

    These should be bytestrings, no?

    1. Nope, doesn't matter. These aren't actually going to contain the binary. They're used when building the SQL statement, which is happy to be Unicode or bytestrings (Django takes care of it). Values don't go in this string. Instead, the database backend is passed the SQL statement and the values, and then does the right thing on its end based on the character set in the database. Then the format string and the values are reconciled.

      Django 1.10, which introduces the _binary fix, uses Unicode here.

  4. djblets/db/backends/mysql/base.py (Diff revision 1)
     
     
    Show all issues

    Bytestring?

  5. 
      
chipx86
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/db/backends/mysql/base.py
    
    Ignored Files:
        djblets/db/backends/__init__.py
        djblets/db/backends/mysql/__init__.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/db/backends/mysql/base.py
    
    Ignored Files:
        djblets/db/backends/__init__.py
        djblets/db/backends/mysql/__init__.py
    
    
  2. 
      
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-0.9.x (6fee6d9)