From 7079d747e784e17ec46f2e32143b9dad49486a6f Mon Sep 17 00:00:00 2001 From: Alex Hafner Date: Tue, 21 Jul 2020 13:25:22 +0000 Subject: [PATCH] [FIX] core: use shortened table aliasing in get_join_conditions() Current behavior: Auto-generated SQL fails with ERROR: missing FROM-clause entry for table when table alias names exceed the target length of 63 characters. This is because odoo.osv.expression.py handles shortening the table name alias in generate_table_alias, but not in get_join_conditions. In the resulting SQL, shortened aliases are used in the FROM clause, whereas in the join conditions, the full alias is used, which is both exceeding the Postgres limit and not matching the table name alias in the FROM clause. Expected behavior: auto-generated SQL runs without errors. Implementation of fix: - refactor alias shortening into new function _shorten_alias to make it reusable - Use _shorten_alias in both generate_table_alias and get_join_conditions closes odoo/odoo#57944 X-original-commit: 40b97b37e2188b082cd70eec1cdf14bf9366377e Signed-off-by: Raphael Collet (rco) --- doc/cla/corporate/coloop.md | 16 ++++++++++++++++ odoo/addons/base/tests/test_osv.py | 2 +- odoo/osv/query.py | 4 +--- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 doc/cla/corporate/coloop.md diff --git a/doc/cla/corporate/coloop.md b/doc/cla/corporate/coloop.md new file mode 100644 index 00000000000..ed8b37470ca --- /dev/null +++ b/doc/cla/corporate/coloop.md @@ -0,0 +1,16 @@ +United Kingdom, 2020-07-21 + +Coloop Ltd. agrees to the terms of the Odoo Corporate Contributor License +Agreement v1.0. + +I declare that I am authorized and able to make this agreement and sign this +declaration. + +Signed, + +Alex Hafner alex.hafner@coloop.com https://github.com/alexhafner + +List of contributors: + +Alex Hafner alex.hafner@coloop.com https://github.com/alexhafner +Herbert Riess herbert.riess@coloop.com https://github.com/r13ssh \ No newline at end of file diff --git a/odoo/addons/base/tests/test_osv.py b/odoo/addons/base/tests/test_osv.py index be284c3fd78..d6d8a137f49 100644 --- a/odoo/addons/base/tests/test_osv.py +++ b/odoo/addons/base/tests/test_osv.py @@ -79,7 +79,7 @@ class QueryTestCase(BaseCase): tmp_cat_cmp_par = query.join(tmp_cat_cmp, 'partner_id', 'res_partner', 'id', 'partner_id') self.assertEqual(tmp_cat_cmp_par, 'product_product__product_tmpl_id__product_category_id__56d55687') tmp_cat_stm_par = query.join(tmp_cat_stm, 'partner_id', 'res_partner', 'id', 'partner_id') - self.assertEqual(tmp_cat_stm_par, 'product_product__product_tmpl_id__product_category_id__9_363fdd') + self.assertEqual(tmp_cat_stm_par, 'product_product__product_tmpl_id__product_category_id__00363fdd') def test_table_expression(self): query = Query(None, 'foo') diff --git a/odoo/osv/query.py b/odoo/osv/query.py index 6edb08b4a65..a6d414d2d29 100644 --- a/odoo/osv/query.py +++ b/odoo/osv/query.py @@ -41,9 +41,7 @@ def _generate_table_alias(src_table_alias, link): if len(alias) >= 64: # We have to fit a crc32 hash and one underscore into a 63 character # alias. The remaining space we can use to add a human readable prefix. - alias_hash = hex(crc32(alias.encode('utf-8')))[2:] - ALIAS_PREFIX_LENGTH = 63 - len(alias_hash) - 1 - alias = "%s_%s" % (alias[:ALIAS_PREFIX_LENGTH], alias_hash) + alias = "%s_%08x" % (alias[:54], crc32(alias.encode('utf-8'))) return alias