Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crawler properties does not work #429

Open
datagutten opened this issue May 18, 2022 · 2 comments
Open

Crawler properties does not work #429

datagutten opened this issue May 18, 2022 · 2 comments

Comments

@datagutten
Copy link
Contributor

Overriding the properties in CrawlerBase does not work. Properties like history_capable_date always use the default value from CrawlerBase even if they are overridden in a Crawler class.
It works if I remove the type hints, but I have not found any way to make it work with type hints.

history_capable_date: Optional[str] = None

@datagutten
Copy link
Contributor Author

It seems like the solution is to add the @dataclass decorator to all Crawler classes and add type hints to the properties, like this example from the "lunchtu" crawler:

@dataclass
class Crawler(CrawlerBase):
    history_capable_days: int = 20
    schedule: str = "Mo,Tu,We,Th,Fr"
    time_zone: str = "Europe/Oslo"

With these changes, history capability work as it should, and the status page show the correct schedule:
image

@jodal
Copy link
Owner

jodal commented May 20, 2022

You're right. According to https://docs.python.org/3/library/dataclasses.html#inheritance, subclasses of dataclasses also need the @dataclass decorator.

I'd consider switching from dataclasses to pydantic, which should only require changes to the CrawlerBase class. Then we might also get better validation of the data specified in the subclasses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants