1

Here my code, in my code, the pipeline only save the item but I tried to delete existing item, it wont work, why this happened?

class ProcessPipeline(object):

def __init__(self):
    self.ids_seen = set()

def process_item(self, item, spider):
    """

    :param item:
    :param spider:
    :return:
    """
    item['website'] = spider.ref_object
    try:
        delete_item = Modelclass.objects.get(name=item['name'])            
        delete_item.delete()
    except Modelclass.DoesNotExist:
        item['website'] = spider.ref_object
        item.save()            
    return item

Any help appreciable, thank you...

1 Answers1

0

I think the problem is in this line then delete_item = Modelclass.objects.get(name=item['name'])

Try debugging that line first. If it's not that, maybe the item is not yielded from the spider. Spider doesn't throw any Exception if it fails to yield an item.

I've tried the delete function. It works.

Aminah Nuraini
  • 18,120
  • 8
  • 90
  • 108