Skip to content

Narrow what gets deferred to Pass 2: inline m2m/o2m to already-existing records #226

Description

@bosd

Follow-up from the code-review discussion around #10 (xmlid-collision preflight, PR #224).

Idea

Today, relational fields (many2many / one2many) are always handled in Pass 2 (after all records are created). But a relation only needs deferral when it points at other rows created in the same import (forward references). A relation pointing at records that already exist in Odoo (e.g. existing res.partner.category tags, an existing country_id) can be written inline in the Pass-1 load() — no deferral, no second write, and crucially no external id required on the owning row.

Why it matters

  • Eliminates a class of the "blank-id row carries relational data" problem feat(#10): pre-flight check for external-id (xmlid) collisions #224 warns about: such rows can carry relations as long as those relations reference existing records — if we stop deferring them.
  • Fewer RPCs (one load() instead of Pass 1 + a Pass-2 write pass) for the common "link to existing masters" case.
  • Simpler, more predictable behaviour.

Sketch

  • During strategy planning (preflight _plan_deferrals_and_strategies / _handle_m2m_field), classify each relational column:
    • references same-import rows (the column's values appear in this file's id column, or it's a self-reference) → keep deferring to Pass 2 (needs the ids created first);
    • references pre-existing records only → keep it in the Pass-1 payload (inline), skip the Pass-2 strategy for it.
  • Requires care for m2m/o2m value formats that load() accepts inline vs. what Pass 2 builds today, and for the (6,0) replace semantics (single-source-of-truth default we're keeping — see the 🌱 Initial Commit - Alpha Release Candidate #14 discussion).

Not urgent

This is an optimization + ergonomics improvement, not a correctness bug (the deferred path works). Filing so it isn't lost.

Refs: #224 (collision preflight), and the #14 additive-relations discussion.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions