Use explicit check for None instead of trueness

In our legacy database we have a primary key (0) which evaluates False,
but is a legitimate value. That causes the autocompleter to fail with an
exception.