Skip to content

Conversation

@Ricardoalso
Copy link
Contributor

@Ricardoalso Ricardoalso commented Jul 18, 2025

connector_importer: take full control of what are the required_keys
Not forcing required default value if required_keys_ignore_mapper and required_keys are defined in options.mapper. Adding the new property required_keys_ignore_mapper in order to override the result of required_keys function

Commit ported from the following fix https://github.com/OCA/connector-interfaces/pull/141/commits to V18

@OCA-git-bot
Copy link
Contributor

Hi @simahawk,
some modules you are maintaining are being modified, check this out!

@simahawk simahawk changed the title [FIX][18.0] connector_importer: proposition of 'fixes' for additional flexibility [FIX][18.0] connector_importer: take full control of what are the required_keys Aug 4, 2025
req = dict(self.required)
req.update(self.work.options.mapper.get("required_keys", {}))

if self.required_keys_ignore_mapper:
Copy link
Contributor

Choose a reason for hiding this comment

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

if this case you should not use update before


@property
def required_keys_ignore_mapper(self):
return self.work.options.mapper.get("required_keys_ignore_mapper", False)
Copy link
Contributor

Choose a reason for hiding this comment

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

If I remember well, we decided to use False as default in prior versions to not alter the behavior of existing import conf. I'd say, we can safely assume that if you are setting required_keys on the mapper you want to take full control anyway.

WDYT?

Copy link
Contributor Author

@Ricardoalso Ricardoalso Aug 7, 2025

Choose a reason for hiding this comment

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

It has been a long time since we discussed this topic, but AFAIR
this was necessary in order to suppress the required name field in the ProductProductMapper https://github.com/OCA/connector-interfaces/blob/18.0/connector_importer_product/components/product_product/mapper.py#L32

The present commit body states:
"Not forcing required default value if required_keys_ignore_mapper and required_keys are defined in options.mapper."

The business use case for this was around updating product.product records with weight and size values provided by an external system. The external system reads the product barcode and creates unique records based on it.
With an import type looking something like:

- model: product.product
  options:
    importer:
      odoo_unique_key: barcode
      override_existing: true
    mapper:
      name: product.product.mapper
      required_keys:
        "Code à barres": barcode
      required_keys_ignore_mapper: true
      source_key_rename:
        "Code à barres": "barcode"

So here required_keys_ignore_mapper and required_keys worked in pair. If we set the default as True, it will ignore the value in self.required 3e9b0c0#diff-1dc9a52e0c26498d8a6b7eeb06f5c031c5f862c67263f047f2cd187be6c37811L55-L56 and create some issues when we use the importer in order to create records if we didn't check all required columns. But I agree required_keys on the mapper should contain all required keys according to the DB schema if we want take full control of it

Not forcing required default value if required_keys_ignore_mapper and required_keys are defined in options.mapper.
Adding the new property required_keys_ignore_mapper in order to override the result of required_keys function
@Ricardoalso Ricardoalso force-pushed the 18_fixes_connector_importer branch from 59e04dc to 3e9b0c0 Compare August 7, 2025 12:08
@github-actions
Copy link

github-actions bot commented Dec 7, 2025

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 7, 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.

4 participants