#19954: Storing of Binary fields leads to Exceptions ----------------------------------------------+-------------------- Reporter: marcel.ryser.ch@… | Owner: nobody Type: Bug | Status: new Component: Database layer (models, ORM) | Version: 1.5 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 ----------------------------------------------+-------------------- I am using a BinaryField on a table to store a binary value
Class for this BinaryField: {{{ class BinaryField(models.TextField): def get_prep_value(self, value): return value; }}} This worked with 1.4 release pretty good. With 1.5 i got this exception {{{ File "C:\Program Files\Python27\lib\site- packages\django\core\handlers\base.py", line 115, in get_response response = callback(request, *callback_args, **callback_kwargs) File "C:\dev\workspace\myproject\Project\src\package\adminviews.py", line 16, in changevalue movie.save() File "C:\Program Files\Python27\lib\site- packages\django\db\models\base.py", line 546, in save force_update=force_update, update_fields=update_fields) File "C:\Program Files\Python27\lib\site- packages\django\db\models\base.py", line 626, in save_base rows = manager.using(using).filter(pk=pk_val)._update(values) File "C:\Program Files\Python27\lib\site- packages\django\db\models\query.py", line 603, in _update return query.get_compiler(self.db).execute_sql(None) File "C:\Program Files\Python27\lib\site- packages\django\db\models\sql\compiler.py", line 1014, in execute_sql cursor = super(SQLUpdateCompiler, self).execute_sql(result_type) File "C:\Program Files\Python27\lib\site- packages\django\db\models\sql\compiler.py", line 840, in execute_sql cursor.execute(sql, params) File "C:\Program Files\Python27\lib\site- packages\django\db\backends\util.py", line 45, in execute sql = self.db.ops.last_executed_query(self.cursor, sql, params) File "C:\Program Files\Python27\lib\site- packages\django\db\backends\mysql\base.py", line 243, in last_executed_query return cursor._last_executed.decode('utf-8') File "C:\Program Files\Python27\lib\encodings\utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 708: invalid start byte }}} This is right, one cannot decode a binary value to utf8 characters. So I saw Ticket #6416 which describes pretty good my problem. I patched the mysql adapter with the code from #6416 and now it works. I don't know exactly on which level this should be fixed, but it is also a problem when it comes to logging of this sql query with a binary field in it, the encoding to bas64 (from code #6416) solves this problem here. -- Ticket URL: <https://code.djangoproject.com/ticket/19954> Django <https://code.djangoproject.com/> 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. For more options, visit https://groups.google.com/groups/opt_out.