OpenUpgrade icon indicating copy to clipboard operation
OpenUpgrade copied to clipboard

[11→12]: psycopg2.ProgrammingError: can't adapt type 'res.company' [stock]

Open nikiwaibel opened this issue 1 year ago • 2 comments

i got this error: psycopg2.ProgrammingError: can't adapt type 'res.company' during the OpenUpgrade process [11→12].

(i am new to openupgrade)

Module

stock

Describe the bug

2024-04-30 07:51:29,525 4446 ERROR odoo12-from11 odoo.sql_db: bad query: UPDATE "stock_rule" SET "company_id"=%s,"write_uid"=%s,"write_date"=%s WHERE id IN %s
ERROR: can't adapt type 'res.company'
2024-04-30 07:51:29,526 4446 ERROR odoo12-from11 OpenUpgrade: stock: error in migration script stock/migrations/12.0.1.1/post-migration.py: can't adapt type 'res.company'
2024-04-30 07:51:29,526 4446 ERROR odoo12-from11 OpenUpgrade: can't adapt type 'res.company'
Traceback (most recent call last):
  File "/home/odoo/venv-3.6-odoo12/lib64/python3.6/site-packages/openupgradelib/openupgrade.py", line 2285, in wrapped_function
    version,
  File "/home/odoo/odoo11to12/OpenUpgrade-12/addons/stock/migrations/12.0.1.1/post-migration.py", line 181, in migrate
    merge_stock_location_path_stock_rule(env)
  File "/home/odoo/odoo11to12/OpenUpgrade-12/addons/stock/migrations/12.0.1.1/post-migration.py", line 98, in merge_stock_location_path_stock_rule
    row[0],
  File "/home/odoo/venv-3.6-odoo12/lib64/python3.6/site-packages/openupgradelib/openupgrade_merge_records.py", line 1036, in merge_records
    _adjust_merged_values_orm(*args2)
  File "/home/odoo/venv-3.6-odoo12/lib64/python3.6/site-packages/openupgradelib/openupgrade_merge_records.py", line 631, in _adjust_merged_values_orm
    target_record.write(new_vals)
2024-04-30 07:51:29,531 4446 ERROR odoo12-from11 odoo.modules.loading: Error executing post migration script for module stock
`-> product_expiry
`-> stock_picking_batch
: can't adapt type 'res.company'

obviously the error happens in OpenUpgrade-12/addons/stock/migrations/12.0.1.1/post-migration.py:merge_stock_location_path_stock_rule(), but i can't make out where exactly; nor i know, if this is caused by sthg that may have modified res.company in the first place or due to something wrong in my odoo-11 stock or due to an error / missing feature in OpenUpgrade-11 ("stock" is marked as "complete" …).

To Reproduce

Affected versions:

  • source system: odoo-11 (fedora26, python-3.6, postgres-9.6)
  • destination system: odoo-12 (fedora-28, python-3.6, postgres-10.7)

Steps to reproduce the behavior:

  1. i removed as much as i could from odoo-11 (some commercial modules like professional_templates - we want to get rif of them anyway)
  2. installed OCB-12 with OCA-12 modules and some others (website_webkul_addons, odoo_shipping_service_apps, …)
  3. createdb odoo12-from11
  4. psql -d odoo12-from11 -f dump.sql >/dev/null
  5. ./odoo11to12/OpenUpgrade-12/odoo-bin -d odoo12-from11 --without-demo=all --addons-path=odoo11to12/OpenUpgrade-12/addons,odoo11to12/commercialAddons,odoo11to12/OCA-12 -D . --update=all --stop-after-init >OpenUpgrade.log 2>&1

Expected behavior update the database from 11 to 12 without error.

Additional context in case the full log is required, just let me know.

nikiwaibel avatar Apr 30 '24 11:04 nikiwaibel

hmm, adding:

(venv-3.6-odoo12) [odoo@odoo12 OpenUpgrade-12]$ git diff
diff --git a/addons/stock/migrations/12.0.1.1/post-migration.py b/addons/stock/migrations/12.0.1.1/post-migration.py
index 5fa957ddccc..9d446cbe470 100644
--- a/addons/stock/migrations/12.0.1.1/post-migration.py
+++ b/addons/stock/migrations/12.0.1.1/post-migration.py
@@ -96,6 +96,7 @@ def merge_stock_location_path_stock_rule(env):
             env, 'stock.rule',
             [row[1]],
             row[0],
+            method="xxx"
         )
     pull_push_rule_ids = tuple(set([r[0] for r in rules_to_merge]))
     if pull_push_rule_ids:

let openupgrade finish.

nikiwaibel avatar May 02 '24 23:05 nikiwaibel

Can't adapt type is a common error. All it means is for example user.company_id is being passed instead of user.company_id.id - it should be trivial to find and fix. If it isn't in the upgrade scripts then it will be a module setting defaults incorrectly or similar.

gdgellatly avatar May 13 '24 20:05 gdgellatly

I ran into this same issue

I found the issue when I have a procurement_rule with a null company id and its trying to merge in a stock_location_path that has a company_id

I can get it to run to completion by adding the following

field_spec={"company_id": "other"}

which just basically still uses the "orm" method but skips the merging of the company_id using merge, so the result is still that the merged records have a null company_id

How do you merge a many2one field when the target field is null but the records that are being merged in have a relationship?

joel-oates avatar Jun 12 '24 23:06 joel-oates

Solved in https://github.com/OCA/openupgradelib/pull/376

pedrobaeza avatar Jun 20 '24 19:06 pedrobaeza