Skip to content

fix: ensure logger is properly initialized in crawling strategies#1387

Closed
takeaship wants to merge 1 commit intounclecode:mainfrom
takeaship:fix-deep-crawling-on-docker-env-error
Closed

fix: ensure logger is properly initialized in crawling strategies#1387
takeaship wants to merge 1 commit intounclecode:mainfrom
takeaship:fix-deep-crawling-on-docker-env-error

Conversation

@takeaship
Copy link
Copy Markdown

@takeaship takeaship commented Aug 10, 2025

Summary

This PR fixes an issue where logger objects are incorrectly serialized/deserialized in Docker environments, causing them to become dictionaries instead of proper logging.Logger instances.

Fixes #1357

List of files changed and why

  • crawl4ai/deep_crawling/bfs_strategy.py - Fixed logger initialization to ensure it remains a proper Logger instance even after serialization/deserialization
  • crawl4ai/deep_crawling/bff_strategy.py - Fixed logger initialization to ensure it remains a proper Logger instance even after serialization/deserialization

How Has This Been Tested?

The fix has been tested by:

  • Verifying that the logger type checking logic properly validates Logger instances
  • Confirming that the fallback mechanism creates a proper Logger when the passed object is not a valid Logger
  • Testing in Docker environment scenarios where object serialization/deserialization occurs

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

Summary by CodeRabbit

  • Refactor
    • Improved the initialization of logging in crawling strategies to ensure type safety and reliability. No changes to user-facing features or behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 10, 2025

Walkthrough

The logger initialization in both BestFirstCrawlingStrategy and BFSDeepCrawlStrategy was updated to include a type check. Now, if a provided logger is not an instance of logging.Logger, the code defaults to using a standard logger, ensuring the attribute is always a valid logger object.

Changes

Cohort / File(s) Change Summary
Logger Initialization Type Check
crawl4ai/deep_crawling/bff_strategy.py, crawl4ai/deep_crawling/bfs_strategy.py
Updated logger initialization in constructors to check type; fallback to default logger if not a logging.Logger instance.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Assessment against linked issues

Objective Addressed Explanation
Ensure logger attributes in deep crawling strategies are always logging.Logger instances (#1357)
Prevent AttributeError from logger objects becoming dictionaries in Docker/deserialization contexts (#1357)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Poem

A logger must log, not become a dict,
In Docker or local, it just must click.
With careful type checks, we’re safe from the fog,
Now crawling strategies happily log.
🐇✨

“No more AttributeErrors!” the rabbit did cheer,
For every log message rings crystal clear.

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5743995 and 6bf6467.

📒 Files selected for processing (2)
  • crawl4ai/deep_crawling/bff_strategy.py (1 hunks)
  • crawl4ai/deep_crawling/bfs_strategy.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • crawl4ai/deep_crawling/bfs_strategy.py
  • crawl4ai/deep_crawling/bff_strategy.py
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
  • 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 src/utils.ts and explain its main purpose.
    • @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 comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 21f79fe and 5743995.

📒 Files selected for processing (2)
  • crawl4ai/deep_crawling/bff_strategy.py (1 hunks)
  • crawl4ai/deep_crawling/bfs_strategy.py (1 hunks)

@takeaship takeaship force-pushed the fix-deep-crawling-on-docker-env-error branch from 5743995 to 6bf6467 Compare August 10, 2025 06:53
@ntohidi
Copy link
Copy Markdown
Collaborator

ntohidi commented Aug 26, 2025

@takeaship Thank you for your contribution. We will incorporate your approach 💜

@takeaship
Copy link
Copy Markdown
Author

Fixed in this PR: #1436

@takeaship takeaship closed this Aug 27, 2025
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]: Deep crawl fails in the Docker environment because Logger objects are converted into dictionaries.

2 participants