def _flatten_q(self, q_object, join_specs, stack=None):
        """Makes a WHERE clause out of a Q object (supports nested Q objects).

        Pass in join_specs(*specs) based on what kind of arguments you think
        the Q object will have.  filter() Qs are different from
        filter_raw() Qs.
        """
        specs = []
        if stack is None:
            stack = [None]
        # TODO(Kumar): construct NOT clause:
        if q_object.negated:
            raise NotImplementedError('negated Q objects')
        connector = q_object.connector

        def add(specs):
            c = join_specs(*specs, connector=connector)
            if (AND, OR) in stack[-1]:
                c = u'(%s)' % (c)
            elif stack[-1] is not None:
                stack.append(connector)
            if c:
                stack.append(c)

        for child in q_object.children:
            if isinstance(child, Node):
                add(specs)
                specs[:] = []
                self._flatten_q(child, join_specs, stack=stack)
            else:
                specs.append(child)
        if len(specs):
            add(specs)
        return u' '.join([c for c in stack if c])
dataset/ETHPy150Open mozilla/addons-server/src/olympia/editors/sql_model.py/RawSQLManager._flatten_q/swapped operands of `in`