Skip to content

Conversation

@peregrine-2024
Copy link

: Resolves infinite loop in BOM computation that was causing 504 Gateway Time-out errors during scheduler execution. Implemented recursion guard mechanism to prevent circular dependency issues where products reference themselves directly or indirectly through component chains. This fix ensures scheduler completion without timeouts while maintaining BOM calculation accuracy. Related to ticket odoo#67931.

Implements a custom module that enhances BOM explosion with robust
recursion guards to prevent infinite loops caused by circular dependencies
in Bill of Materials structures.

Key features:
- Maximum recursion depth limit (100 levels) to prevent stack overflow
- Early cycle detection using visited products set for O(1) lookup
- Enhanced DFS-based cycle detection in BOM graph traversal
- Detailed error messages showing exact product chains causing cycles
- Comprehensive logging for debugging and monitoring
- Zero core Odoo modifications (follows inheritance best practices)

Technical implementation:
- Inherits from mrp.bom model
- Overrides explode() method with enhanced protection
- Tracks product chains throughout recursion
- Maintains visited products set to detect cycles early
- Provides clear, actionable error messages to users

Fixes: Damage Control QA server 504 Gateway Time-out issue
Ticket: 67931
Module: mrp_bom_cycle_guard
Version: 16.0.1.0.0
@peregrine-2024
Copy link
Author

🛠️ Automated Fix: MRP BOM Cycle Guard Implementation

This pull request implements the MRP BOM Cycle Guard module to resolve the recurring 504 Gateway Time-out errors experienced on the Damage Control QA server during BOM explosion processes.

✅ Changes Summary

The following files were added and modified to introduce robust cycle detection and recursion guards in the mrp.bom model:


🔧 addons/mrp_bom_cycle_guard/models/mrp_bom.py
  • New Model Override: Overrides the explode() method in the mrp.bom model to enhance safety against infinite loops.
  • Key Enhancements:
    • Introduces MAX_RECURSION_DEPTH constant (default: 100) to prevent stack overflows.
    • Implements cycle detection using DFS traversal with a visited_products set for fast O(1) lookups.
    • Tracks the product chain during explosion to provide detailed error messages.
    • Logs debug information for troubleshooting BOM computation issues.
  • Error Handling:
    • Raises a UserError with descriptive messages when:
      • Excessive recursion depth is detected.
      • Circular dependencies are found in the BOM structure.
  • Performance Optimizations:
    • Early cycle detection prevents unnecessary processing.
    • Efficient graph traversal reduces overhead for normal BOMs.

📄 addons/mrp_bom_cycle_guard/README.md
  • Comprehensive Documentation:
    • Explains the problem: 504 timeouts due to circular BOM dependencies.
    • Describes the solution with technical details including:
      • Recursion depth tracking
      • Cycle detection via DFS
      • Enhanced error reporting
      • Performance improvements
    • Includes usage instructions, configuration options, and example error output.
    • Provides guidance on viewing logs for debugging.

📦 addons/mrp_bom_cycle_guard/__manifest__.py
  • Module Metadata:
    • Defines module name, version, category, summary, and description.
    • Specifies dependency on the mrp module.
    • Sets installability and application flags appropriately.

📁 addons/mrp_bom_cycle_guard/__init__.py & addons/mrp_bom_cycle_guard/models/__init__.py
  • Initialization Files:
    • Ensures proper module imports for models.mrp_bom.

🧪 Testing & Review Notes

  • The new logic has been tested to ensure it correctly identifies and blocks circular BOM structures without breaking standard BOM explosions.
  • It is recommended to test this module in a staging environment with known problematic BOMs to validate error handling and logging behavior.
  • Ensure compatibility with existing workflows and verify that valid BOM structures continue to function as expected.

📌 Ticket Reference

Helpdesk Ticket #67931
Resolves: Damage Control QA server 504 Gateway Time-out


This change ensures system stability and improves maintainability by preventing infinite loops during BOM explosion, especially in environments with complex or malformed BOM configurations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants