Skip to content

Defferred import of related fields should not be triggered for required fields #18

Description

@bosd

When a import is invoked on a model with related fields, the pre-flight mechanism takes care of detecting the relational fields.
The relational fields are then defferred and imported at pass 2.
For most odoo models this is ok. But not for models, with rely heavily on the relation.
On those models the related field is made required, when we defer the import to those fields there is an error:
example:

sh res_partner_bank_local.sh
[11:44:52] INFO     Starting data import process from file...                                                                                                                                                                                       importer.py:111
           INFO     Running pre-flight check: Verifying Odoo connection...                                                                                                                                                                          preflight.py:93
           INFO     Connecting to Odoo server at localhost...                                                                                                                                                                                        conf_lib.py:40
           INFO     Connection to Odoo successful.                                                                                                                                                                                                  preflight.py:99
           INFO     Running pre-flight check: Detecting self-referencing hierarchy...                                                                                                                                                              preflight.py:121
           INFO     No self-referencing hierarchy detected.                                                                                                                                                                                        preflight.py:145
           DEBUG    Skipping language pre-flight check.                                                                                                                                                                                            preflight.py:251
           INFO     Running pre-flight check: Verifying fields for model 'res.partner.bank'...                                                                                                                                                     preflight.py:467
           INFO     Loading fields_get cache for model 'res.partner.bank' from cache.                                                                                                                                                                  cache.py:131
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ReadOnly Fields Detected ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ The following readonly fields will be silently ignored during import:                                                                                                                                                                                           │
│   - 'id' (stored readonly integer)                                                                                                                                                                                                                              │
│   - 'company_id/id' (stored readonly many2one)                                                                                                                                                                                                                  │
│                                                                                                                                                                                                                                                                 │
│ Values for these fields will be silently discarded during import.                                                                                                                                                                                               │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
           INFO     Pre-flight Check Successful: All columns are valid fields on the model.                                                                                                                                                        preflight.py:499
           DEBUG    Reusing cached connection for conf/local_connection.conf                                                                                                                                                                         conf_lib.py:66
           DEBUG    Initialized RPC thread pool with requested 1 connections, effectively using 1 to prevent connection pool exhaustion                                                                                                            rpc_thread.py:40
⠋    Pass 1/2: Importing to res.partner.bank                                                    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━                                                       0%        •    0 of 1 batches                    •    0:00:00                  DEBUG    Attempting `load` for chunk of batch 1...                                                                                                                                                                                import_threaded.py:659
WARN: Batch 1 failed `load` ('Missing required value for the field 'Account Holder' (partner_id)'). Falling back to `create` for 131 records.
     Pass 1/2: Importing to res.partner.bank                                                    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━  

Solution: We should only defer the import of related fields if they are NOT required.
on models like res.partner.bank where the partner_id is required, we should import that in one pass.
The pre-flight check needs to be modified to detect this situation and choose the correct method accordingly.

note:
After enhancing the functionality. test sessions which are run in nox should pass. Additional tests should be created to cover this use case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    JulesGoogle Jules

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions