Skip to content

Django KeyError <class 'bytes'> in version 1.4.0rc1 #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dev-artisan opened this issue Dec 11, 2018 · 11 comments
Closed

Django KeyError <class 'bytes'> in version 1.4.0rc1 #306

dev-artisan opened this issue Dec 11, 2018 · 11 comments
Labels

Comments

@dev-artisan
Copy link

Hi,
Just updated my dev server to the latest version (1.4.0rc1) and my Django server crashed when trying to connect to the local MySQL DB installed on Ubuntu server v16
The error occurs in the code below from django/db/backends/mysql/base.py

def get_new_connection(self, conn_params):
        conn = Database.connect(**conn_params)
        conn.encoders[SafeText] = conn.encoders[six.text_type]
        conn.encoders[SafeBytes] = conn.encoders[bytes]
        return conn

Specifically this line
conn.encoders[SafeBytes] = conn.encoders[bytes]

I've reverted back to 1.13.14 and all is well in the world again, hope this helps
Thanks
Omar

@methane
Copy link
Member

methane commented Dec 12, 2018

Thank you for testing RC. It's intended, minor backward incompatible chage.
And the code is removed in Django almost two years ago.
django/django@5b95d42#diff-dbe1511db54b8fff2cb72a199cf37b4c

You need to update Django if you want to use new mysqlclient.

@methane methane closed this as completed Dec 12, 2018
@keviny
Copy link

keviny commented Jan 18, 2019

How to resolve this?

@methane
Copy link
Member

methane commented Jan 18, 2019

Update Django.

@dev-artisan
Copy link
Author

How to resolve this?

If you're like me and want to stay on long term Django release 1.11, don't update this library to version 1.4.
Stick to version 1.3.14 until you decide to update to Django 2

@fsh905
Copy link

fsh905 commented Jan 22, 2019

I met the same problem,

File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 276, in get_new_connection
    conn.encoders[SafeBytes] = conn.encoders[bytes]
KeyError: <type 'str'>

salved by update mysqlclient from 1.4.1 to 1.3.14

bz2 added a commit to bz2/django-prometheus that referenced this issue Jan 22, 2019
Upstream changes are incompatible with older Django versions, see:

    PyMySQL/mysqlclient#306
AlexHill pushed a commit to AlexHill/django-naivedatetimefield that referenced this issue Jan 23, 2019
mysqlclient 1.4.0 has a problem with Django below version 2. See PyMySQL/mysqlclient#306
SSPJ added a commit to openedx-unsupported/blockstore that referenced this issue Jan 28, 2019
@beamerblvd
Copy link

I would like to formally protest to the "Upgrade Django" sentimentality, on two fronts.

First, 1.4.0 is a minor release. According to Semver, introducing backwards-incompatible changes in a minor release is not permitted. By putting a breaking change in 1.4.0, and then denying this is a problem and telling people to upgrade Django, this project is publicly stating that it does not care about / does not adhere to Semver.

Second, Django 1.11 is still a supported version of Django. It is in LTS. Telling people to "Upgrade Django" might be warranted if this error appeared only in a very old, unsupported version of Django (such as 1.5, 1.6, etc.), but Django 1.11 is still LTS until April 2020. In fact, Django 1.11 is the newest version of Django that is in LTS. Django 2.0 and 2.1 support will actually end before Django 1.11 support ends. Django 2.2 isn't out yet. So, one can rightly argue that Django 1.11 is the "current" version of Django, support-wise.

Literally tens of thousands, maybe hundreds of thousands, of developers and sys admins worldwide depend on either Django 1.11 or MySQLClient-Python, and a substantial subset of those depend on both of them together. This cavalier disregard for those developers by introducing a breaking change in a minor release is disheartening.

In my strongly-held opinion, this breaking change should be reverted and that revert immediately released in 1.4.2, and the breaking change should be introduced only in MySQLClient-Python 2.0, in accordance with Semver.

@methane
Copy link
Member

methane commented Jan 30, 2019

Django touched many undocumented or private part of mysqlclient. It caused this crash. But I don't think it's a serious backward incompatibility of mysqlclient-python. Backward compatibility is supported only when public APIs are used, and don't relay on internal strucutre.

Additionally, Django 1.11 doesn't support mysqlclient-1.3.14+ already. See these commit and comment.

Since Django 1.11 doesn't support mysqlclient-1.4 at first, there are no reason to add workaround for Django 1.11 in mysqlclient 1.4.

If Django maintainer want Django works with mysqlclient-1.3.14+ and 1.4.1+, I am OK to add some workaround in mysqlclient.

If you want to use Django 1.11 with mysqlclient 1.4+, discuss with Django maintainers about it and backport django/django#10726 to Django 1.11.

@methane
Copy link
Member

methane commented Jan 30, 2019

Second, Django 1.11 is still a supported version of Django.

It is not trully supported. It is security fix only mode. It doesn't fix any issues including this.

the breaking change should be introduced only in MySQLClient-Python 2.0, in accordance with Semver.

It is impossible. When I change query slightly for bugfix, it can be "breaking change" for some people.
And even removing unused private variable broke Django 1.11!

If I follow semver strongly, it means I need to increment major number every time. It doesn't make happy anyone.
It is difficult to know when really big breaking change comes (e.g. dropping Python 2 support).
And people need to pin version anyway.

So this project never follow semver. It doesn't make any sense.


But I'm thinking how to work around these breakage, not for semver, but for Django 1.11 users.

If you're interested in contributing this project for Django user, please send pull request to add
travis test running Django test. I don't have motivation for it because I'm not a Django user.

@methane
Copy link
Member

methane commented Feb 1, 2019

Everyone complain when theoricary backward-compatible change caused crash
because of Django implementation. But no one contributes.

OSS maintainer is very frustrating job.

@kierun
Copy link

kierun commented Feb 1, 2019

OSS maintainer is very frustrating job.

Yes, it is. And your efforts are appreciated (at least by me!) as well as all your past hard work. If you want, I can test your PR with my setup which has the same error.

To be fair, Django developers should use you API not private variables. Doing so is beyond stupid.

LTR are great because you do not have to justify work to "update to the latest release" every time a new one is released. It is bad because you have to do a whole chunk later on but at least it's a one off.

methane added a commit that referenced this issue Feb 7, 2019
Django touched private area of this library.
Removing unused variables broke Django.

While Django 2.0 fixed it, Django 1.11 doesn't fix it
because it is in security-only fix mode.

So add unused variables for Django 1.11 compatibility.
They will be removed in next minor release.

Fix #303, #306
@methane
Copy link
Member

methane commented Feb 15, 2019

1.4.2post1 fixed this issue. Passes Django 1.11 test suite.

@methane methane closed this as completed Feb 15, 2019
korfuri pushed a commit to korfuri/django-prometheus that referenced this issue Jun 13, 2019
* Pin prometheus-client to <0.4.0

Fixes #83

Simple dependency change that will fix tests and can be released as
a working package. Follow up can adapt to the interface and metric
name changes in 0.4.0 and depend on that version.

* Pin mysqlclient to <1.4

Upstream changes are incompatible with older Django versions, see:

    PyMySQL/mysqlclient#306
@methane methane mentioned this issue Jan 8, 2021
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants