[Django] #27816: Duplicate keyword '_binary' failure when using BinaryField with mysql backend

6 views
Skip to first unread message

Django

unread,
Feb 7, 2017, 3:21:53 AM2/7/17
to django-...@googlegroups.com
#27816: Duplicate keyword '_binary' failure when using BinaryField with mysql
backend
-------------------------------------+-------------------------------------
Reporter: Ace Han | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 1.10
layer (models, ORM) |
Severity: Normal | Keywords: BinaryField mysql
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Although it's bad design in 99% of the cases, my project just need to
store file in db anyway

Below is my code
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
# models.py
class DbBasedFile(models.Model):
filename = models.CharField(_('filename'), max_length=128)
content = models.BinaryField(_('content'))
size = models.PositiveIntegerField(_('size'))

class Meta:
unique_together = (('filename', ), )

def __str__(self):
return '{}, filename: {}'.format(self.__class__.__name__,
self.filename)

if __name__ == '__main__':
DbBasedFile(filename='1.txt', content=b'abc', size=3).save()
}}}
}}}

will get error
{{{
ProgrammingError at /api/misc/dbfiles/file/
(1064, "You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'_binary'abc', 3)'
}}}

The pre-generated sql is like below
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
str: INSERT INTO `misc_dbbasedfile` (`filename`, `content`, `size`)
VALUES (%s, _binary %s, %s)
}}}
}}}

The final sql is like below
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
bytes: b"INSERT INTO `misc_dbbasedfile` (`filename`, `content`, `size`)
VALUES ('1.txt', _binary _binary'abc', 3)"
}}}
}}}

As we can see, there are two ''''_binary''' in the final sql which will
fail eventually

After a little debugging, I found these '''_binary''' in

{{{
django/django/db/backends/mysql/operations.py.DatabaseOperations.binary_placeholder_sql
django/db/models/fields/__init__.py.BinaryField.get_placeholder
}}}

, which I think is the root cause


Please kindly help to fix it, thx.

--
Ticket URL: <https://code.djangoproject.com/ticket/27816>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 7, 2017, 7:04:33 AM2/7/17
to django-...@googlegroups.com
#27816: Duplicate keyword '_binary' failure when using BinaryField with mysql
backend
-------------------------------------+-------------------------------------
Reporter: Ace Han | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution:

Keywords: BinaryField mysql | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Are you using the latest version of mysqlclient? There's
[https://github.com/PyMySQL/mysqlclient-python/pull/106 a bug] in some
older versions.

--
Ticket URL: <https://code.djangoproject.com/ticket/27816#comment:1>

Django

unread,
Feb 7, 2017, 8:51:08 PM2/7/17
to django-...@googlegroups.com
#27816: Duplicate keyword '_binary' failure when using BinaryField with mysql
backend
-------------------------------------+-------------------------------------
Reporter: Ace Han | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution:
Keywords: BinaryField mysql | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Ace Han):

Replying to [comment:1 Tim Graham]:


> Are you using the latest version of mysqlclient? There's
[https://github.com/PyMySQL/mysqlclient-python/pull/106 a bug] in some
older versions.

Hi,
I just went with {{{PyMySQL==0.7.9}}}, I don't know there is a
{{{mysqlclient}}}.
However, I would prefer {{{PyMySQL}}} for its python implementation.

Anyway, isn't this issue related with {{{django}}} itself in
{{{django/django/db/backends/mysql}}}?

--
Ticket URL: <https://code.djangoproject.com/ticket/27816#comment:2>

Django

unread,
Feb 8, 2017, 7:00:16 AM2/8/17
to django-...@googlegroups.com
#27816: Duplicate keyword '_binary' failure when using BinaryField with mysql
backend
-------------------------------------+-------------------------------------
Reporter: Ace Han | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: BinaryField mysql | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid


Comment:

I think PyMySQL needs to adapt as explained in [https://github.com/PyMySQL
/mysqlclient-python/pull/106 the mysqlclient issue]. By the way, it's not
an officially supported or tested adapter by Django.

--
Ticket URL: <https://code.djangoproject.com/ticket/27816#comment:3>

Reply all
Reply to author
Forward
0 new messages