Skip to content

Conversation

@sagu-odoo
Copy link
Contributor

@sagu-odoo sagu-odoo commented Nov 29, 2025

  1. This commit Add param type_check get the common columns info with same typcategory or same data type and skipp the column with different datatype and different type

  2. all column name should be returned

Traceback (most recent call last):
  File "/home/odoo/src/odoo/19.0/odoo/service/server.py", line 1514, in preload_registries
    registry = Registry.new(dbname, update_module=update_module, install_modules=config['init'], upgrade_modules=config['update'], reinit_modules=config['reinit'])
  File "/home/odoo/src/odoo/19.0/odoo/tools/func.py", line 88, in locked
    return func(inst, *args, **kwargs)
  File "/home/odoo/src/odoo/19.0/odoo/orm/registry.py", line 186, in new
    load_modules(
  File "/home/odoo/src/odoo/19.0/odoo/modules/loading.py", line 493, in load_modules
    migrations.migrate_module(package, 'end')
  File "/home/odoo/src/odoo/19.0/odoo/modules/migration.py", line 220, in migrate_module
    exec_script(self.cr, installed_version, pyfile, pkg.name, stage, stageformat[stage] % version)
  File "/home/odoo/src/odoo/19.0/odoo/modules/migration.py", line 257, in exec_script
    mod.migrate(cr, installed_version)
  File "/tmp/tmp7yriz79e/migrations/hr/saas~18.4.1.1/end-migrate.py", line 87, in migrate
    cr.execute(query, [e[1] for e in required_default_values])
  File "/home/odoo/src/odoo/19.0/odoo/sql_db.py", line 426, in execute
    self._obj.execute(query, params)
psycopg2.errors.DatatypeMismatch: column "fondo_ahorro" is of type boolean but expression is of type double precision
LINE 16: ..."."distance_home_work_unit", "e"."employee_type", "e"."fondo...
                                                              ^
HINT:  You will need to rewrite or cast the expression.
select id,name,model,ttype,store from ir_model_fields where name='fondo_ahorro';
  id   |     name     |         model         |  ttype  | store
-------+--------------+-----------------------+---------+-------
 28361 | fondo_ahorro | hr.employee           | float   | t
 28687 | fondo_ahorro | calculo.liquidaciones | float   | t
 28379 | fondo_ahorro | hr.version            | boolean | t
(3 rows)

upg-3444635
opw-5260147

@robodoo
Copy link
Contributor

robodoo commented Nov 29, 2025

Pull request status dashboard

@sagu-odoo sagu-odoo requested review from a team and diagnoza November 29, 2025 05:37
@sagu-odoo sagu-odoo changed the title [FIX] util/pg: get only common name with type [FIX] util/pg: get only common name with same type Nov 29, 2025
@sagu-odoo
Copy link
Contributor Author

upgradeci retry with always only base

@aj-fuentes
Copy link
Contributor

You should output a warning when a common column has a different type and it is skipped.
IMO current patch is too specific for custom DBs, if you output a warning you would ensure that this mistake doesn't make us leave columns behind that should have been moved.
@KangOl ?

@sagu-odoo
Copy link
Contributor Author

sagu-odoo commented Dec 1, 2025

But getting info of column with respect of column_type make sense (if the defination is not matching). So, what is the meaning of moving them ?.

@aj-fuentes
Copy link
Contributor

I don't understand your question. I will clarify my point instead.

You are silently skipping the moving of columns that have compatible types (think float and numeric or int). This could lead to unexpectedly now loosing some information that was previously moved correctly. If you put a warning line in the logs this will achieve a twofold goal. First we block the CI, standard data won't have a silent change of behavior. Second, on actual upgrade requests we leave a trace in the logs to debug if this issue affects clients.

@sagu-odoo
Copy link
Contributor Author

sagu-odoo commented Dec 1, 2025

Hello @aj-fuentes , what about this if we use this to categories data type and then find common column?.

EDIT:

test=# \d test_1
                   Table "public.test_1"
 Column |       Type       | Collation | Nullable | Default 
--------+------------------+-----------+----------+---------
 id     | double precision |           |          | 
 name   | text             |           |          | 

test=# \d test_2
                    Table "public.test_2"
 Column |       Type        | Collation | Nullable | Default 
--------+-------------------+-----------+----------+---------
 id     | integer           |           |          | 
 name   | character varying |           |          | 

test=# WITH _cols AS (
    SELECT  c.table_name, c.column_name, t.typcategory
      FROM information_schema.columns c
      JOIN pg_type t ON c.udt_name = t.typname
     WHERE table_schema = 'public'
       AND table_name IN ('test_1', 'test_2')
),                              
_common AS (
    SELECT column_name
      FROM _cols
     GROUP BY column_name, typcategory
    HAVING COUNT(table_name) = 2
) select * from _common;
 column_name 
-------------
 id
 name
(2 rows)

@aj-fuentes
Copy link
Contributor

aj-fuentes commented Dec 1, 2025

Yes, using typcategory seems better, but I would keep a warning.

  1. If the types are incompatible (different category) -> warn we skipped them
  2. It the types are different but compatible -> warn about the different type (we still return them in the list of common columns)

I think both cases may require attention when they happen. At the very least we are sure we get a trace in the logs.

@sagu-odoo sagu-odoo force-pushed the master-fix_get_column_name_by_type-sagu branch 2 times, most recently from 6e0d631 to 4462ff8 Compare December 1, 2025 13:30
Copy link
Contributor

@aj-fuentes aj-fuentes left a comment

Choose a reason for hiding this comment

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

I think we can make the query much simpler and do the filtering in Python.

@sagu-odoo sagu-odoo force-pushed the master-fix_get_column_name_by_type-sagu branch from 4462ff8 to 202e591 Compare December 2, 2025 04:33
@aj-fuentes
Copy link
Contributor

upgradeci retry with always *hr* *mrp* in versions 18.0 19.0

@sagu-odoo sagu-odoo force-pushed the master-fix_get_column_name_by_type-sagu branch from 202e591 to a05a92c Compare December 2, 2025 08:16
@aj-fuentes
Copy link
Contributor

upgradeci skip

@aj-fuentes
Copy link
Contributor

upgradeci retry with always l10n_*_hr_* hr_* *_mrp in versions 18.0 19.0

@aj-fuentes
Copy link
Contributor

upgradeci skip

@aj-fuentes
Copy link
Contributor

upgradeci retry with l10n_*_hr_* hr_* mrp in versions 18.0 19.0

src/util/pg.py Outdated
Comment on lines 1238 to 1241
SELECT column_name,
quote_ident(column_name),
count(DISTINCT t.oid) = 1 AS same_type,
count(DISTINCT t.typcategory) = 1 AS compatible
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
SELECT column_name,
quote_ident(column_name),
count(DISTINCT t.oid) = 1 AS same_type,
count(DISTINCT t.typcategory) = 1 AS compatible
SELECT column_name,
quote_ident(column_name),
count(DISTINCT t.oid) = 1 AS same_type,
count(DISTINCT t.typcategory) = 1 AS compatible
Suggested change
SELECT column_name,
quote_ident(column_name),
count(DISTINCT t.oid) = 1 AS same_type,
count(DISTINCT t.typcategory) = 1 AS compatible
SELECT c.column_name,
quote_ident(c.column_name),
count(DISTINCT t.oid) = 1 AS same_type,
count(DISTINCT t.typcategory) = 1 AS compatible

src/util/pg.py Outdated
:param str table2: second table name whose columns are retrieved
:param list(str) ignore: list of column names to ignore in the returning list
:return: a list of column names present in both tables
:return: a list of column names present in both tables with compatible data type
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add an option to return all the common columns, regardless of their types?

Suggested change
:return: a list of column names present in both tables with compatible data type
:param bool type_check: only returns common columns with compatible data type
:return: a list of column names present in both table

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done with suggested changes. could you please have a another look ?.

@sagu-odoo sagu-odoo force-pushed the master-fix_get_column_name_by_type-sagu branch 5 times, most recently from 8ca3c17 to b252009 Compare December 3, 2025 10:59
src/util/pg.py Outdated


def get_common_columns(cr, table1, table2, ignore=("id",)):
def get_common_columns(cr, table1, table2, ignore=("id",), type_check=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be True by default. @KangOl ?

Suggested change
def get_common_columns(cr, table1, table2, ignore=("id",), type_check=False):
def get_common_columns(cr, table1, table2, ignore=("id",), type_check=True):

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, indeed.

src/util/pg.py Outdated
AND c.column_name != ALL(%s)
GROUP BY c.column_name
HAVING count(c.table_name) = 2
ORDER BY c.column_name
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct indent

Suggested change
ORDER BY c.column_name
ORDER BY c.column_name

@sagu-odoo sagu-odoo force-pushed the master-fix_get_column_name_by_type-sagu branch from b252009 to e321d93 Compare December 4, 2025 09:44
src/util/pg.py Outdated
Comment on lines 1306 to 1311
common_columns = [
name for name, _, same_type, compatible in cols_info if compatible or (type_check and not same_type)
]
quoted_common_columns = [
qname for _, qname, same_type, compatible in cols_info if compatible or (type_check and not same_type)
]
Copy link
Contributor

Choose a reason for hiding this comment

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

The filtering condition is wrong, it should be not type_check or compatible
To avoid duplication, we can use zip

Suggested change
common_columns = [
name for name, _, same_type, compatible in cols_info if compatible or (type_check and not same_type)
]
quoted_common_columns = [
qname for _, qname, same_type, compatible in cols_info if compatible or (type_check and not same_type)
]
common_columns, quoted_common_columns = zip(
*((name, qname) for name, qname, _, compatible in cols_info if not type_check or compatible)
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but I have checked it was working the same but this one is straight forward. Thanks for the review

1. This commit Add param ``type_check``
get the common columns info with same typcategory or
same data type and skipp the column with different
datatype and different type

2. all column name should be returned

```
Traceback (most recent call last):
  File "/home/odoo/src/odoo/19.0/odoo/service/server.py", line 1514, in preload_registries
    registry = Registry.new(dbname, update_module=update_module, install_modules=config['init'], upgrade_modules=config['update'], reinit_modules=config['reinit'])
  File "/home/odoo/src/odoo/19.0/odoo/tools/func.py", line 88, in locked
    return func(inst, *args, **kwargs)
  File "/home/odoo/src/odoo/19.0/odoo/orm/registry.py", line 186, in new
    load_modules(
  File "/home/odoo/src/odoo/19.0/odoo/modules/loading.py", line 493, in load_modules
    migrations.migrate_module(package, 'end')
  File "/home/odoo/src/odoo/19.0/odoo/modules/migration.py", line 220, in migrate_module
    exec_script(self.cr, installed_version, pyfile, pkg.name, stage, stageformat[stage] % version)
  File "/home/odoo/src/odoo/19.0/odoo/modules/migration.py", line 257, in exec_script
    mod.migrate(cr, installed_version)
  File "/tmp/tmp7yriz79e/migrations/hr/saas~18.4.1.1/end-migrate.py", line 87, in migrate
    cr.execute(query, [e[1] for e in required_default_values])
  File "/home/odoo/src/odoo/19.0/odoo/sql_db.py", line 426, in execute
    self._obj.execute(query, params)
psycopg2.errors.DatatypeMismatch: column "fondo_ahorro" is of type boolean but expression is of type double precision
LINE 16: ..."."distance_home_work_unit", "e"."employee_type", "e"."fondo...
                                                              ^
HINT:  You will need to rewrite or cast the expression.
```

```
select id,name,model,ttype,store from ir_model_fields where name='fondo_ahorro';
  id   |     name     |         model         |  ttype  | store
-------+--------------+-----------------------+---------+-------
 28361 | fondo_ahorro | hr.employee           | float   | t
 28687 | fondo_ahorro | calculo.liquidaciones | float   | t
 28379 | fondo_ahorro | hr.version            | boolean | t
(3 rows)
```

upg-3444635
opw-5260147
@sagu-odoo sagu-odoo force-pushed the master-fix_get_column_name_by_type-sagu branch from e321d93 to 54bf0e6 Compare December 4, 2025 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants