Guard against null tree_ids

Since None is a 'valid' tree id for this view function, we need to
handle it first