-
Notifications
You must be signed in to change notification settings - Fork 81
[FIX] util/pg: get only common name with same type #359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[FIX] util/pg: get only common name with same type #359
Conversation
|
upgradeci retry with always only base |
|
You should output a warning when a common column has a different type and it is skipped. |
|
But getting info of column with respect of |
|
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. |
|
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) |
|
Yes, using
I think both cases may require attention when they happen. At the very least we are sure we get a trace in the logs. |
6e0d631 to
4462ff8
Compare
aj-fuentes
left a comment
There was a problem hiding this 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.
4462ff8 to
202e591
Compare
|
202e591 to
a05a92c
Compare
|
upgradeci skip |
|
|
upgradeci skip |
|
src/util/pg.py
Outdated
| SELECT column_name, | ||
| quote_ident(column_name), | ||
| count(DISTINCT t.oid) = 1 AS same_type, | ||
| count(DISTINCT t.typcategory) = 1 AS compatible |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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 |
| 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 |
There was a problem hiding this comment.
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?
| :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 |
There was a problem hiding this comment.
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 ?.
8ca3c17 to
b252009
Compare
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): |
There was a problem hiding this comment.
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 ?
| def get_common_columns(cr, table1, table2, ignore=("id",), type_check=False): | |
| def get_common_columns(cr, table1, table2, ignore=("id",), type_check=True): |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct indent
| ORDER BY c.column_name | |
| ORDER BY c.column_name |
b252009 to
e321d93
Compare
src/util/pg.py
Outdated
| 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) | ||
| ] |
There was a problem hiding this comment.
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
| 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) | |
| ) |
There was a problem hiding this comment.
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
e321d93 to
54bf0e6
Compare

This commit Add param
type_checkget the common columns info with same typcategory or same data type and skipp the column with different datatype and different typeall column name should be returned
upg-3444635
opw-5260147