id and slug values have diverged, but our code flip-flops between them.  Both are still unique (and we check that assumption), so workaround is to assign id to slug.
Merge branch 'topictree_id_workaround' into control_panel
removing pdb (sigh), finally fixing up headless_* semi-properly.
efficiency changes, import cleaning, adding comments, per @jamalex code review