@@ -357,25 +357,21 @@ def _queue_deferred_x2m_import(self, field, comodel, value):
357357 return True
358358
359359 def _get_yaml_duplicate_reference_dict (self , ref , values ):
360- """Return YAML payload when this record was already serialized in the export .
360+ """Return the stub emitted when a record has already been serialized .
361361
362- The collector deduplicates by (model, reference) and otherwise emits only
363- ``{"reference": ...}``. Nested one2many rows may be imported before the
364- full record exists; ``create`` still needs required scalars (e.g. ``name``) .
362+ The collector deduplicates by (model, reference); subsequent occurrences
363+ are collapsed to a reference-only dict. Import must never attempt to create
364+ from this stub — it must resolve the record by reference instead .
365365
366366 Args:
367367 ref (str): Record reference.
368- values (dict): Raw values from :meth:`~odoo.models.Model.read` before
369- YAML post-processing .
368+ values (dict): Raw values (unused; kept for signature compatibility
369+ in case subclasses need them) .
370370
371371 Returns:
372- dict: Minimal stub safe for import when a duplicate appears in the same
373- file.
372+ dict: ``{"reference": ref}`` only.
374373 """
375- stub = {"reference" : ref }
376- if values .get ("name" ):
377- stub ["name" ] = values ["name" ]
378- return stub
374+ return {"reference" : ref }
379375
380376 def _post_process_record_values (self , values ):
381377 """Post process record values
@@ -732,18 +728,18 @@ def _update_or_create_related_record(
732728
733729 # If the record does not exist, create a new one
734730 else :
731+ if set (values .keys ()) == {"reference" }:
732+ _logger .warning (
733+ "Attempted to import a record for model '%s' "
734+ "with reference "
735+ "'%s', but only the 'reference' field was provided. "
736+ "Creation will be skipped until the target record "
737+ "exists." ,
738+ model ._name ,
739+ reference ,
740+ )
741+ return False
735742 if create_immediately :
736- if set (values .keys ()) == {"reference" }:
737- _logger .warning (
738- "Attempted to import a record for model '%s' "
739- "with reference "
740- "'%s', but only the 'reference' field was provided. "
741- "Creation will be skipped until the target record "
742- "exists." ,
743- model ._name ,
744- reference ,
745- )
746- return False
747743 record = model .with_context (from_yaml = True ).create (
748744 model ._post_process_yaml_dict_values (values )
749745 )
@@ -753,20 +749,20 @@ def _update_or_create_related_record(
753749
754750 # If there's no reference but value is a dict, create a new record
755751 else :
756- if create_immediately :
757- # Only 'reference' provided, no other data: do not create,
758- # just log warning
759- if set (values .keys ()) == {"reference" }:
760- _logger .warning (
761- "Attempted to import a record for model '%s' with reference "
762- "'%s', but only the 'reference' field was provided. "
763- "It is possible that this record has already been imported. "
764- "Creation will be skipped." ,
765- model ._name ,
766- reference ,
767- )
768- return False
752+ # Only 'reference' provided, no other data: do not create,
753+ # just log warning
754+ if set (values .keys ()) == {"reference" }:
755+ _logger .warning (
756+ "Attempted to import a record for model '%s' with reference "
757+ "'%s', but only the 'reference' field was provided. "
758+ "It is possible that this record has already been imported. "
759+ "Creation will be skipped." ,
760+ model ._name ,
761+ reference ,
762+ )
763+ return False
769764
765+ if create_immediately :
770766 record = model .with_context (from_yaml = True ).create (
771767 model ._post_process_yaml_dict_values (values )
772768 )
0 commit comments