Skip to content

fix: use None defaults for boolean base_config fields - #2227

Open
dajiaohuang wants to merge 1 commit into
unclecode:mainfrom
dajiaohuang:fix/2121-base-config-boolean-defaults
Open

fix: use None defaults for boolean base_config fields#2227
dajiaohuang wants to merge 1 commit into
unclecode:mainfrom
dajiaohuang:fix/2121-base-config-boolean-defaults

Conversation

@dajiaohuang

Copy link
Copy Markdown

Fixes #2121 - Boolean values in crawler.base_config (like simulate_user, magic, override_navigator, check_robots_txt, remove_overlay_elements) were silently ignored because their dataclass defaults of False caused the guard check to fail.

Problem

When the client doesn't send a field, it gets the dataclass default. The check 'current_value is None or current_value == ""' failed for False because False is neither None nor "".

Solution

Change defaults from False to None for these fields in CrawlerRunConfig. Now None means 'not set by client' and False means 'explicitly set to False'. The check in api.py is simplified to 'if current_value is None'.

Files changed

  • crawl4ai/async_configs.py: Change defaults for simulate_user, magic, override_navigator, check_robots_txt, remove_overlay_elements, remove_consent_popups from False to None
  • deploy/docker/api.py: Simplify check from 'current_value is None or current_value == ""' to 'current_value is None'

Fixes unclecode#2121 - Boolean values in crawler.base_config (like
simulate_user, magic, override_navigator, check_robots_txt,
remove_overlay_elements) were silently ignored because their
dataclass defaults of False caused the guard check to fail.

When the client doesn't send a field, it gets the dataclass default.
The check 'current_value is None or current_value == ""' failed for
False because False is neither None nor "".

Solution: Change defaults from False to None for these fields. Now
None means 'not set by client' and False means 'explicitly set to
False'. The check in api.py is simplified to 'if current_value is None'.
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

Successfully merging this pull request may close these issues.

[Bug]: crawler.base_config boolean values are silently ignored (regression from #1505)

1 participant