Skip to content

Conversation

@georgiedekker
Copy link

Summary

This PR fixes an installation error in the product_warranty module that occurs when the _get_default_instructions method tries to query the return_instruction table during field initialization, but the table doesn't exist yet.

Problem

During module installation, Odoo initializes model fields before all tables are created. The product.supplierinfo model has a return_instructions field with a default value computed by _get_default_instructions(), which tries to query the return_instruction table. This causes the following error:

psycopg2.errors.UndefinedTable: relation "return_instruction" does not exist

Solution

Wrap the search query in a try/except block to gracefully handle the missing table during installation by returning False instead of raising an exception. Once the installation completes and the table exists, the method works normally.

Testing

  • Added comprehensive unit tests to verify the fix handles both installation and normal operation scenarios
  • All existing tests pass
  • Pre-commit hooks pass
  • Module installs successfully with this fix

Test plan

  • Install the product_warranty module on a fresh database - should install without errors
  • Verify that default return instructions are properly set after installation
  • Run existing test suite to ensure no regression
  • New tests verify both error handling and normal operation

🤖 Generated with Claude Code

georgiedekker and others added 7 commits August 11, 2025 10:00
In Odoo 18, the model 'stock.production.lot' has been renamed to 'stock.lot'.
This commit updates all references to use the new model name:
- Updated model inheritance in Python files
- Updated view references from stock.view_production_lot_form to stock.view_lot_form
- Updated test references to use stock.lot instead of stock.production.lot
Fixed the inherited view reference from stock.view_lot_form to
stock.view_production_lot_form which is the correct XML ID in Odoo 18.

The module now successfully installs and works with Odoo 18.
- Replace psycopg2.IntegrityError with ValidationError/ValueError exceptions
- Add mute_logger decorator to suppress SQL error logs in tests
- Add flush_recordset() calls to ensure constraint checks are triggered
- Update test expectations to match Odoo 18 behavior

The tests were failing because Odoo 18 handles database constraints differently,
requiring updates to exception handling in the test cases.
…Odoo 18

- Replace tuple exception handling with try-except blocks
- Odoo 18's assertRaises doesn't accept tuples of exceptions
- Use try-except to handle both ValidationError and IntegrityError
- Fix line length issues for pre-commit compliance

The tests were failing with 'TypeError: issubclass() arg 1 must be a class'
because Odoo 18's test framework doesn't support passing multiple exception
types to assertRaises.
…rmatting

- Replace 'pass' in except blocks with proper assertions
- Use error_raised flag to avoid pylint W8138 warning
- Apply ruff formatting to ensure consistent code style
- All pre-commit checks now pass

This ensures the code meets OCA quality standards and CI requirements.
…n table

When installing the product_warranty module, an error occurs because the
_get_default_instructions method tries to query the return_instruction
table during field initialization, but the table doesn't exist yet.

This fix wraps the search query in a try/except block to gracefully
handle the missing table during installation by returning False instead
of raising an exception.

The issue manifests with the following error:
psycopg2.errors.UndefinedTable: relation "return_instruction" does not exist

After this fix, the module installs successfully and the default
instructions are properly set once the table is created.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Dec 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale PR/Issue without recent activity, it'll be soon closed automatically.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant