Skip to content

Commit

Permalink
Make it possible to (de)serialize request
Browse files Browse the repository at this point in the history
  • Loading branch information
majnaber committed Jan 20, 2025
1 parent fdb2050 commit 1ab87eb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions scrapfly/scrapy/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ def __init__(self, scrape_config:ScrapeConfig, meta:Dict={}, *args, **kwargs):
**kwargs
)

def to_dict(self, spider=None):
"""
Override to_dict to handle serialization with scrape_config.
The spider argument is ignored to maintain compatibility with Scrapy.
"""
d = super().to_dict() # Call the parent class's to_dict
d['scrape_config'] = self.scrape_config
return d

@classmethod
def from_dict(cls, d):
"""
Override from_dict to handle deserialization of scrape_config.
"""
scrape_config = d.pop('scrape_config', None)
return cls(scrape_config=scrape_config, **d)

def replace(self, *args, **kwargs):
for x in [
'meta',
Expand Down

0 comments on commit 1ab87eb

Please sign in to comment.