Fixed #22959, #23473

https://code.djangoproject.com/ticket/22959
https://code.djangoproject.com/ticket/23473