Skip to content

Fix: Exclude deprecated properties from CrawlResult serialization #1356

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

petebytes
Copy link

@petebytes petebytes commented Aug 2, 2025

Summary

This PR fixes a serialization issue in the CrawlResult class where deprecated properties were causing AttributeError exceptions during model serialization.

Problem

The CrawlResult class has three deprecated properties (markdown_v2, fit_markdown, and fit_html) that raise AttributeError when accessed. When calling model_dump() on the model, Pydantic attempts to access these properties during serialization, causing the process to fail with:

AttributeError: The 'markdown_v2' attribute is deprecated and has been removed.

This particularly affects API usage where the CrawlResult needs to be serialized to JSON.

Solution

The fix modifies the model_dump() method to explicitly exclude these deprecated properties from serialization. This prevents Pydantic from attempting to access them.

Implementation details:

  • Define a set of deprecated properties to exclude: {'markdown_v2', 'fit_markdown', 'fit_html'}
  • Properly merge this exclusion set with any existing exclusions passed to model_dump()
  • Handle different types of exclude parameters (set, list, or other)

Testing

The fix ensures that:

  • Models can be serialized without errors even when deprecated properties are present
  • Existing exclude parameters are preserved and merged correctly
  • Backward compatibility is maintained

Related Issues

This fix prevents the serialization errors that occur when using the CrawlResult model with deprecated property definitions, particularly in API contexts.

Summary by CodeRabbit

  • Bug Fixes
    • Deprecated properties are now excluded from the serialized output of crawl results, ensuring cleaner and more accurate data presentation to users.

- Add explicit exclusion of deprecated properties (markdown_v2, fit_markdown, fit_html)
  in CrawlResult.model_dump() method
- Prevents AttributeError when serializing models that contain these deprecated properties
- Properly handles merging with existing exclude parameters
Copy link
Contributor

coderabbitai bot commented Aug 2, 2025

Walkthrough

The model_dump method in the CrawlResult class was updated to always exclude certain deprecated properties from serialization, regardless of user input. The method now merges these exclusions with any provided exclusions, ensuring non-serializable properties are omitted from the output.

Changes

Cohort / File(s) Change Summary
CrawlResult Serialization
crawl4ai/models.py
Updated model_dump to always exclude deprecated/non-serializable properties (markdown_v2, fit_markdown, fit_html) from output, merging with user-provided exclusions. No changes to method signature or class interface.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CrawlResult
    participant JSONResponse

    User->>CrawlResult: Call model_dump(kwargs)
    CrawlResult->>CrawlResult: Merge deprecated properties into exclude set
    CrawlResult->>CrawlResult: Prepare serializable dict (excluding non-serializable properties)
    CrawlResult->>JSONResponse: Return serializable output
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Assessment against linked issues

Objective Addressed Explanation
Prevent inclusion of non-serializable objects (like property types) in the response payload (#1343)
Fix crash during JSON serialization by excluding unserializable properties from result (#1343)
Ensure the crawler returns a JSON-serializable error message or status instead of crashing (#1343)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Poem

A hop and a skip, some code to revise,
Deprecated props now meet their demise.
No more crashes, no more pain—
JSON flows smooth, like a gentle rain.
🐇✨ Serialization’s neat,
Bugs retreat—what a treat!

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 04191a5 and f1866dc.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • crawl4ai/models.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crawl4ai/models.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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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
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: 0

🧹 Nitpick comments (1)
crawl4ai/models.py (1)

255-267: LGTM! Solid fix for the serialization issue.

The implementation correctly addresses the core problem by excluding deprecated properties that raise AttributeError during serialization. The logic properly handles different types of exclude parameters.

Minor suggestion for robustness:

Consider preserving unknown exclude parameter types rather than replacing them entirely:

         else:
-            kwargs['exclude'] = exclude_properties
+            # For unknown types, try to combine if possible, otherwise use deprecated properties
+            try:
+                kwargs['exclude'] = set(kwargs['exclude']) | exclude_properties
+            except (TypeError, ValueError):
+                kwargs['exclude'] = exclude_properties

This would handle edge cases where users might pass custom exclude objects that support set operations.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e328193 and 04191a5.

📒 Files selected for processing (1)
  • crawl4ai/models.py (1 hunks)

- Try to convert unknown exclude types to set before replacing
- Preserves user-specified exclusions when possible
- More graceful error handling as suggested in PR review
@aravindkarnam aravindkarnam changed the base branch from main to develop August 19, 2025 11:13
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]: JSON serialization error
1 participant