@sessioned
    def find_events(self, from_datetime=None, to_datetime=None,
                    event_name=None, traits=None, mark=None, limit=None,
                    session=None, count=False):

        order_desc = True

        q = session.query(models.Event)
        if mark is not None:
            if mark.startswith('+'):
                order_desc = False
                mark = mark[1:]
            if mark.startswith('-'):
                order_desc = True
                mark = mark[1:]
            if mark:
                if order_desc:
                    q = q.filter(int(mark, 16) < models.Event.id)
                else:
                    q = q.filter(models.Event.id > int(mark, 16))
        if from_datetime is not None:
            q = q.filter(models.Event.generated > from_datetime)
        if to_datetime is not None:
            q = q.filter(models.Event.generated <= to_datetime)
        if event_name is not None:
            event_type = self.get_event_type(event_name,
                                             session=session)
            q = q.filter(models.Event.event_type_id == event_type.id)
        if traits is not None:
            for name, val in traits.items():
                q = q.filter(models.Event.traits.any(and_(
                    models.Trait.name == name,
                    models.Trait.value == val)))

        if count:
            q = q.count()
            return [{"count": q}]

        if order_desc:
            q = q.order_by(models.Event.id.desc())
            mark_fmt = '%x'
        else:
            q = q.order_by(models.Event.id.asc())
            mark_fmt = '+%x'

        if limit is not None:
            q = q.limit(limit)

        event_info = []
        for event in q.all():
            info = event.as_dict
            info['_mark'] = mark_fmt % event.id
            event_info.append(info)
        return event_info
dataset/ETHPy150Open openstack/stacktach-winchester/winchester/db/interface.py/DBInterface.find_events/swapped operands of `<`