Skip to content

[16.0][IMP] Protect against contract line add/ remove in same db transaction#1303

Open
fcayre wants to merge 1 commit intoOCA:16.0from
commown:16.0-imp-contract_forecast-allow-create-delete-cline-in-same-transaction
Open

[16.0][IMP] Protect against contract line add/ remove in same db transaction#1303
fcayre wants to merge 1 commit intoOCA:16.0from
commown:16.0-imp-contract_forecast-allow-create-delete-cline-in-same-transaction

Conversation

@fcayre
Copy link
Member

@fcayre fcayre commented Sep 17, 2025

In such a situation, a queue job is created but crashes. This patch avoids the crash.

@fcayre fcayre changed the title Protect against contract line add/ remove in same db transaction [16.0][IMP] Protect against contract line add/ remove in same db transaction Sep 18, 2025
In such a situation, a queue job is created but crashes. This patch
avoids the crash.
@fcayre fcayre force-pushed the 16.0-imp-contract_forecast-allow-create-delete-cline-in-same-transaction branch from 1cdc4a7 to 92bafb1 Compare October 16, 2025 06:40
Copy link

@Honeyxilia Honeyxilia left a comment

Choose a reason for hiding this comment

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

Code review OK

Copy link

@marcos-mendez marcos-mendez left a comment

Choose a reason for hiding this comment

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

Automated Review -- Tests Failed

1. Root Cause

The test failure is caused by a missing or uninstalled module required by contract_forecast, likely contract or a related dependency. The error occurs during registry loading when Odoo tries to install the contract_forecast module but fails due to an unresolved dependency.


2. Suggested Fix

Ensure that the contract module (or any required dependencies) is included in the depends list of contract_forecast's __manifest__.py. Without this, Odoo cannot resolve the models referenced in contract_line.py.

File: contract_forecast/__manifest__.py
Change: Add 'contract' to the depends list if not already present.


3. Additional Code Issues

  • Potential performance issue in _generate_forecast_periods:
    The code calls rec.forecast_period_ids.unlink() inside a loop without batching. If many contract lines are processed, this may cause performance degradation. However, this is not a bug per se, but a performance consideration.

  • No handling of rec.recurring_next_date being False:
    While the code checks if rec.recurring_next_date:, it doesn't explicitly handle the case where rec.recurring_next_date is False or None. This is safe due to Python's truthiness, but could be made more explicit for clarity.


4. Test Improvements

Add a TransactionCase or SavepointCase test to cover the following scenarios:

  • Test with a contract line that has no recurring_next_date

    • Ensure no error occurs and no forecast periods are created.
  • Test with a contract line that has recurring_next_date set

    • Verify that forecast_period_ids are properly created or updated.
  • Test with a batch of contract lines (multiple records)

    • Ensure self.exists() prevents processing deleted records.

Example test method (in test_contract_line.py):

def test_generate_forecast_periods_no_recurring_next_date(self):
    contract_line = self.env['contract.line'].create({
        'name': 'Test Line',
        'recurring_next_date': False,
    })
    contract_line._generate_forecast_periods()
    # Assert no forecast periods created

Use @tagged('post_install', 'manual_install') for tests involving module installation dependencies.


⏰ PR Aging Alert

This PR by @fcayre has been open for 179 days (5 months).
💤 Last activity was 87 days ago.

Every ignored PR is a contributor who might not come back. Review time matters. (OCA Aging Report)


Reciprocal Review Request

Hi everyone! I found some test failures on this PR and left detailed feedback above. I am happy to discuss or help debug. In the meantime, if any of you get a chance, I would appreciate a look at my open PR(s):

My open PRs across OCA:

Reviewing each other's work helps the whole community move forward. Thank you!


Environment via OCA Neural Reviewer: Minikube + K8s Job + oca-ci/py3.10-odoo16.0 | Odoo 16.0
Automated review by OCA Neural Reviewer + qwen3-coder:30b

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.

3 participants