Fixed #23660 -- Moved sort_dependencies to core.

https://code.djangoproject.com/ticket/23660