db(query)(other if cond else None).select()
improved ipv6 address checked, thanks Jonathan