These two lines are one and the same. Only exceptions are different. Actually get()implemented on top one(). It would be a difference if yours filter()returned more than the result, but this is really impossible in your case.
By the way, SQL does not have a GET operation, it only has SELECT (with optional LIMIT).
sqlalchemy / orm / query.py :
def get(self, ident):
...
return self._get_impl(ident, loading.load_on_ident)
sqlalchemy / orm / loading.py :
def load_on_ident(query, key,
refresh_state=None, lockmode=None,
only_load_props=None):
...
try:
return q.one()
except orm_exc.NoResultFound:
return None
q.one() q.one_or_none().
first() one_or_none()
def first(self):
...
ret = list(self[0:1])
if len(ret) > 0:
return ret[0]
else:
return None
def one_or_none(self):
...
ret = list(self)
l = len(ret)
if l == 1:
return ret[0]
elif l == 0:
return None
else:
raise orm_exc.MultipleResultsFound(
"Multiple rows were found for one_or_none()")
, first() SELECT LIMIT, one_or_none() SELECT. , , LIMIT, , , .