Skip to content

fix(docker): resolve filter serialization and JSON encoding errors in deep crawl strategy#1436

Merged
ntohidi merged 2 commits intodevelopfrom
fix/docker-filter
Aug 27, 2025
Merged

fix(docker): resolve filter serialization and JSON encoding errors in deep crawl strategy#1436
ntohidi merged 2 commits intodevelopfrom
fix/docker-filter

Conversation

@ntohidi
Copy link
Copy Markdown
Collaborator

@ntohidi ntohidi commented Aug 25, 2025

Summary

Fixed Docker server filter serialization and JSON encoding errors when using deep crawl strategies with filter chains. The server was returning 500 errors when FilterChain was specified in BFSDeepCrawlStrategy, and filters were not being properly applied during crawling.

Fixed DeepCrawlStrategy fails with AttributeError when max_pages limit is reached in Docker mode.

Fixed Deep crawl fails in the Docker environment because Logger objects are converted into dictionaries.

Fixes #1419, #1437, #1357

List of files changed and why

  • crawl4ai/async_configs.py - Removed serialization of private slots attributes that were incorrectly being passed as constructor parameters during deserialization
  • crawl4ai/deep_crawling/filters.py - Added public attributes to URLPatternFilter to store original constructor parameters for proper serialization/deserialization
  • crawl4ai/models.py - Fixed model_dump() to handle property descriptors that were causing "Object of type property is not JSON serializable" errors

How Has This Been Tested?

Tested with a comprehensive test suite covering:

  1. Docker Client Test: Verified that Crawl4aiDockerClient can successfully serialize and send filter chains to the server without TypeErrors
  2. REST API Test: Confirmed that direct REST API calls with filter chain payloads work correctly
  3. Round-trip Serialization: Ensured filter chains maintain all properties through serialization/deserialization cycle
  4. Real URL Filtering: Tested with actual websites (GitHub, Stack Overflow, Python.org, Wikipedia) to verify filters correctly block/allow URLs based on patterns
  5. Deep Crawl Execution: Validated that BFSDeepCrawlStrategy with filters successfully crawls and filters URLs (tested with docs.crawl4ai.com, filtering for "core" pattern - correctly returned 21 matching
    URLs)

Test scenarios included:

  • Pattern matching with reverse filters (about, privacy, terms)
  • Complex filter chains with 13+ patterns
  • Max depth and max pages limits
  • Both streaming and non-streaming modes

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added/updated unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

… deep crawl strategy (ref #1419)

  - Fix URLPatternFilter serialization by preventing private __slots__ from being serialized as constructor params
  - Add public attributes to URLPatternFilter to store original constructor parameters for proper serialization
  - Handle property descriptors in CrawlResult.model_dump() to prevent JSON serialization errors
  - Ensure filter chains work correctly with Docker client and REST API

  The issue occurred because:
  1. Private implementation details (_simple_suffixes, etc.) were being serialized and passed as constructor arguments during deserialization
  2. Property descriptors were being included in the serialized output, causing "Object of type property is not JSON serializable" errors

  Changes:
  - async_configs.py: Comment out __slots__ serialization logic (lines 100-109)
  - filters.py: Add patterns, use_glob, reverse to URLPatternFilter __slots__ and store as public attributes
  - models.py: Convert property descriptors to strings in model_dump() instead of including them directly
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 25, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/docker-filter

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

1 participant