diff options
| author | Denis Vermylen <dve@odoo.com> | 2019-12-09 15:30:50 +0000 |
|---|---|---|
| committer | Denis Vermylen <dve@odoo.com> | 2019-12-24 19:08:11 +0000 |
| commit | cf0146934d5377ae4b65a46fe86fbb21ab6ec7cb (patch) | |
| tree | 2cc20ce04a64f631b2a0df3db4f8d869c5699f48 | |
| parent | 193040ada2cd8e94a04383bbfea7f56a1a19340e (diff) | |
[FIX] sql_db: ignore PG views when verifying table type
Collisions in table names of ORM models with built-in PG structures such
as "attributes", "domains", "routines", "parameters", ... could occur
and render the result of `table_kind` meaningless.
Based on what was done via https://github.com/odoo/odoo/pull/16651 more
than 2 years ago, it seems relying on our tables being in the 'public'
schema is safe, even though it's only a default from PG. We reuse that
same logic rather than the alternative of excluding
('information_schema', 'pg_catalog', ...), even though it looks safer at
first. If we did the latter we'd have to change the other comparison for
consistency, i.e. more risks.
closes odoo/odoo#42358
X-original-commit: d8e74eb14990c82f65a44ffe163aa84159d6ccc4
Signed-off-by: Denis Vermylen <Icallhimtest@users.noreply.github.com>
| -rw-r--r-- | odoo/tools/sql.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/odoo/tools/sql.py b/odoo/tools/sql.py index 28cbe3ab25f..1c3fa9e98a4 100644 --- a/odoo/tools/sql.py +++ b/odoo/tools/sql.py @@ -38,7 +38,13 @@ def table_kind(cr, tablename): ``'f'`` (foreign table), ``'t'`` (temporary table), ``'m'`` (materialized view), or ``None``. """ - query = "SELECT relkind FROM pg_class WHERE relname = %s" + query = """ + SELECT c.relkind + FROM pg_class c + JOIN pg_namespace n ON (n.oid = c.relnamespace) + WHERE c.relname = %s + AND n.nspname = 'public' + """ cr.execute(query, (tablename,)) return cr.fetchone()[0] if cr.rowcount else None |
