'Return the first element of the first result or None
if no rows present.  If multiple rows are returned,
raises MultipleResultsFound.
>>> session.query(Item).scalar()
<Item>
>>> session.query(Item.id).scalar()
1
>>> session.query(Item.id).filter(Item.id < 0).scalar()
None
>>> session.query(Item.id, Item.name).scalar()
1
>>> session.query(func.count(Parent.id)).scalar()
20
This results in an execution of the underlying query.'

def scalar(self):

    try:
        ret = self.one()
        if (not isinstance(ret, tuple)):
            return ret
        return ret[0]
    except orm_exc.NoResultFound:
        return None
