def get_users_account(account=None, profile=None): for acct in Account.select(): if not _check(acct.profile, profile): continue if not _check(acct, account): continue break else: raise ValueError('Account not found') return UserAccount.from_account(acct.id)