crawl4ai icon indicating copy to clipboard operation
crawl4ai copied to clipboard

fix: guard against None values in _apply_transform

Open jnMetaCode opened this issue 8 months ago • 0 comments

Summary

JsonCssExtractionStrategy._apply_transform() crashes with AttributeError when value is None. This happens when a CSS or XPath selector finds no matching element — the extracted value is None, and calling .lower(), .upper(), or .strip() on it raises:

AttributeError: 'NoneType' object has no attribute 'lower'

Changes

  • extraction_strategy.py: Added an early return guard at the start of _apply_transform:
    if value is None:
        return value
    

Impact

Without this fix, any extraction schema with transforms will crash on pages where optional fields are missing. This is a common scenario when scraping heterogeneous pages. The fix allows transforms to gracefully pass through None values.

jnMetaCode avatar Mar 08 '26 04:03 jnMetaCode