def iterator(self):
        """
        An iterator over the results from applying this QuerySet to the
        remote web service.
        """
        try:
            sql, params = SQLCompiler(self.query, connections[self.db], None).as_sql()
        except EmptyResultSet:
            raise StopIteration
        cursor = CursorWrapper(connections[self.db], self.query)
        cursor.execute(sql, params)

        pfd = prep_for_deserialize

        only_load = self.query.get_loaded_field_names()
        load_fields = []
        # If only/defer clauses have been specified,
        # build the list of fields that are to be loaded.
        if not only_load:
            model_cls = self.model
            init_list = None
        else:
            fields = self.model._meta.concrete_fields
            for field in fields:
                model = field.model._meta.concrete_model
                if model is None:
                    model = self.model
                try:
                    selected_name = field.attname if DJANGO_18_PLUS else field.name
                    if selected_name in only_load[model]:
                        # Add a field that has been explicitly included
                        load_fields.append(field.name)
                except __HOLE__:
                    # Model wasn't explicitly listed in the only_load table
                    # Therefore, we need to load all fields from this model
                    load_fields.append(field.name)

            init_list = []
            skip = set()
            for field in fields:
                if field.name not in load_fields:
                    skip.add(field.attname)
                else:
                    init_list.append(field.name)
            model_cls = deferred_class_factory(self.model, skip)

        field_names = self.query.get_loaded_field_names()
        for res in python.Deserializer(pfd(model_cls, r, self.db, init_list) for r in cursor.results):
            # Store the source database of the object
            res.object._state.db = self.db
            # This object came from the database; it's not being added.
            res.object._state.adding = False
            yield res.object
dataset/ETHPy150Open django-salesforce/django-salesforce/salesforce/backend/query.py/SalesforceQuerySet.iterator