Commit Graph
57 Commits
Author SHA1 Message Date
Albin 0f56c0f0be [FIX] core: env creation broken because of missing cr.transaction
A cursor created by a Connection object is not expected to be used with
environments; use registry.cursor() instead.

closes odoo/odoo#78143

X-original-commit: 6aeb73f10953f3547b7cf830718c02a3933df9e0
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-10-11 11:27:46 +00:00
Raphael Collet db25704b75 [FIX] service: autocommit when creating database
Creating a database from the Odoo CLI miserably fails with the error
"psycopg2.ProgrammingError: set_session cannot be used inside a
transaction".

Setting con.autocommit = True fails if some transaction is already
started, which is the case when creating a database.  The fix consists
in rolling back the existing transaction (with only a SELECT) before
switching to autocommit.

closes odoo/odoo#68549

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-03-30 12:54:05 +00:00
Raphael Collet 3816601819 [FIX] service: autocommit
Following 7a235c19ff, use an alternative
API to the method autocommit().  Several functions managing databases
use a connection in autocommit mode to execute some commands outside of
a transaction.

closes odoo/odoo#68491

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-03-30 09:36:50 +00:00
Xavier Morel 4688b2dd9d [FIX] core: mis-updated SQL queries
odoo/odoo#53938 improved the SQL linter and used psycopg2.sql to
silence the linter where that still made sense. However I forgot to
mark table names (pretty much exclusively) as `sql.Identifier` in a
few somewhat rare callsites, which consequently break when invoked as
a simple string is not a Composable and psycopg2 therefore rejects it
when composing the query.

odoo/odoo#54556 fixed a few mis-updated ones, but apparently I still
managed to miss one here.

closes odoo/odoo#56191

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-08-20 09:02:48 +00:00
Xavier Morel 65b8751e32 [FIX] core: mis-updated SQL queries
odoo/odoo#53938 improved the SQL linter and used psycopg2.sql to
silence the linter where that still made sense. However I forgot to
mark table names (pretty much exclusively) as `sql.Identifier` in a
few somewhat rare callsites, which consequently break when invoked as
a simple string is not a Composable and psycopg2 therefore rejects it
when composing the query.

closes odoo/odoo#54556

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-07-16 09:10:03 +00:00
Xavier Morel e162e6f714 [FIX] test_lint, *: false negative in sql injection linter
The linter would miss / fail to warn on injection of *local variables*
in some cases.

Try to improve it to be stricter and more reliable, after discussion
with odo, sql which is "correctly" dynamic should use psycopg2's sql
package in order to bypass the linter (bonus: it should also properly
escape & quote identifiers).

closes odoo/odoo#53938

Related: odoo/enterprise#11718
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-07-10 07:12:35 +00:00
Damien Bouvy 9702142204 [IMP] odoo: avoid useless error in logs
Avoid logging an error in the logs for an operation that is not an

closes odoo/odoo#48957

Error: if the extension already exists, this is a success.
X-original-commit: 2f884942c94a640ae5107ff2acb27ba4ecc60bc0
Signed-off-by: Damien Bouvy (dbo) <dbo@odoo.com>
2020-04-03 10:27:12 +00:00
Nils Hamerlinck b381b0eb6f [IMP] db: install unaccent extension on new databases
The unaccent extension was installed only at restore, not at creation
of a database.
Make both consistent.

closes odoo/odoo#46534

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2020-03-10 16:50:06 +00:00
Xavier Morel 355e360973 [IMP] core: mark a few osutil functions as deprecated
* walksymlinks is useless, os.walk got followlinks in 2.6
* tempdir is redundant with tempfile.TemporaryDirectory added in 3.2
* listdir(recursive=False) is just os.listdir (I guess recursive=True
  is somewhat useful)
* zip_dir is *not* redundant with shutil.make_archive:
  - zip_dir handles the archived root differently
  - zip_dir sorts files, make_archive sorts directories
  - make_archive explicitly adds entries for directories (including
    empty), sorts directories, doesn't sort files; zip_dir sorts
    files (including with a custom key function) but ignores directories
  - zip_dir filters out a bunch of trash files

closes odoo/odoo#39573

Signed-off-by: Christophe Simonis <chs@odoo.com>
2019-10-30 11:02:41 +00:00
Raphael Collet c7f5c4afd2 [FIX] sql_db: add flush() in savepoint()
closes odoo/odoo#36060

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-08-26 13:39:16 +00:00
Adrian Torres 52f5528cfb [REF] *: replace deprecated pycompat helpers for builtins
This commit replaces calls to pycompat helpers that were intended for
python 2 <-> python 3 interoperability for python 3 builtins, as python
2 is no longer officially supported by Odoo.

This includes:
    * calls to imap/izip/ifilter replaced by map/zip/filter
    * uses of text_type replaced by str
    * uses of unichr replaced by chr
    * calls to implements_to_string, implements_iterator removed
    * string_types and integer_types replaced by str, int respectively
    * calls to to_native replaced by calls to to_text

This is done in preparation to the removal of these deprecated helpers
in the following commit.
2018-11-29 09:28:17 +00:00
David Arnold 1bf58d282f [IMP] db: set default user tz through country code
Given a country code is specified and the country only has one timezone, it is
safe to assume that the admin user is operating from that timezone.

Set the default timezone to simplify the onboarding in such particular case.

If a country has more than one timezone, we can not make safe assumptions and
don't provide a default tz.

closes odoo/odoo#26365
2018-10-26 07:21:47 +00:00
Antony Lesuisse 62644f93fe [IMP] base: onboarding prefill email in company data 2018-10-01 16:38:00 +02:00
Christophe Monniez 83e460b8da [IMP] web: add a phone input to the database manager
Task: 1879675
2018-09-18 13:54:19 +02:00
Raphael Collet d72ca98593 [FIX] odoo: db manager configures user_admin 2018-08-24 11:03:24 +02:00
Christophe Simonis 7499b47ffa [MERGE] forward port branch saas-11.4 up to edd586002e 2018-08-10 13:37:21 +02:00
Christophe Simonis 932b229941 [MERGE] forward port branch 11.0 up to b29e053436 2018-08-06 11:46:10 +02:00
Christophe Simonis b29e053436 [MERGE] forward port branch saas-15 up to 43eca3079e 2018-08-06 11:32:12 +02:00
Christophe Simonis 43eca3079e [MERGE] forward port branch saas-14 up to 1f92477cf4 2018-08-06 11:01:50 +02:00
Lucas Perais (lpe) e17bc4eb37 [FIX] base: set currency on a new db
Open the web/database/manager and create a db with a country set.

The country of the first company will be set to the country set on the form

Before this commit, the currency was not set, eventhough it is a field
on res.country

After this commit, we also set the currency of the first company

opw 1869435
closes #26097
2018-08-01 14:40:39 +02:00
Olivier Dony 3edd504f17 [IMP] db: create new databases based on template0
As a follow-up to commit 276ea817f4,
we change the default template database used for CREATE DATABASE
operations, and we avoid setting the LC_COLLATE option unless
this default template is used (to avoid locale compatibility errors).

Rationale for the default template choice:

PostgreSQL uses `template1` by default, and recommends that users alter
`template1` if they need a custom template, while keeping template0
virgin. This is likely to be the reason why we had `template1` as the
default previously (from a1e5c645d9).

However, for new Odoo databases, it's actually better to use `template0`
as template, for multiple reasons:
- We do not customize the template database, and the system will work
  fine when starting from a completely virgin database
- Since template0 does not allow connections by default, we have a
  stronger guarantee that no user will be connected to the template
  database (which would otherwise block database creations!)
- We use the same logic for creating new databases and for creating
  placholder databases for restoring dumps. In the latter case,
  PostgreSQL recommends using a virgin template, to obtain a perfect
  copy of the database being restored (unaffected by any template
  customization)
- Using `template0` as a template lets us choose any encoding and locale
  settings (LC_COLLATE/LC_CTYPE) upon creation. Any other database
  template might cause errors unless we select compatible encodings
  and locale settings.
  As the locale setting is system-dependent, we can't just hope
  that there will be no compatibility problem, we must explicitly
  default to template0. Therefore the change in
  276ea817f4 was prone to causing
  locale compatibility errors.

Finally, if users have a reason to prefer a different template, they
should select it explicitly with the --db_template config.

Note: existing environments will likely continue to use `template1`
as a default due to presence of older config files.

Complements #25196
2018-06-29 16:37:42 +02:00
Moisés López 276ea817f4 [IMP] db: force C collation for new databases
This makes sorting and indexing independent of the cluster/machine
configuration, and allows simple b-tree indexes to be used for
prefix-searches on VARCHAR columns without needing special operator
classes (and therefore without needing duplicate indexes).

The 'C' collation is built-in and always available on any postgresql
installation. It also allows any encoding/locale to be used, contrary to
other LC_COLLATE values, so it should never conflict with custom db
templates.

Admins who want to apply a special collation can still do so by creating
the database manually, instead of letting the system do it.

Closes #25196
2018-06-29 13:06:30 +02:00
Christophe Simonis b170a753e1 [MERGE] forward port branch 11.0 up to b05e4d5f95 2018-06-15 10:15:27 +02:00
Andreas Perhab bb8ded772a [FIX] db: close connection of incompatible DB only
Close connections of incompatible databases instead of closing all
connections.

Introduced in 610036756a

Closes #24479
opw-1852793
2018-06-12 18:26:35 +02:00
Christophe Simonis 56974322f8 [MERGE] forward port branch 11.0 up to 3b80a059ff 2018-01-12 19:03:00 +01:00
Christophe Simonis b42b9c936b [MERGE] forward port branch saas-16 up to 3b7bf3a4b8 2018-01-12 18:15:23 +01:00
Christophe Simonis 3b7bf3a4b8 [MERGE] forward port branch saas-15 up to 8962b8ecc2 2018-01-12 17:23:10 +01:00
Christophe Simonis 8962b8ecc2 [MERGE] forward port branch saas-14 up to d35a76ee17 2018-01-12 16:47:12 +01:00
Jerther 270b2ebf81 [FIX] service, web: memory error on large DB
Fixes MemoryError when restoring large database archive.

Closes #17663
opw-788273
2018-01-12 10:17:42 +01:00
Alexandre Kühn 9cd1cae65f [FIX] odoo service: fix location of res_country_data.xml file
It has been moved inside base/data, instead of base/res.
We have to adapt code that is calling it.
2017-11-29 09:04:12 +01:00
Christophe Monniez 0fdf291305 [REF] db: simplify list_dbs
When trying to list db's, the db_user is searched and verified before
searching for the databases.
As it's enclosed in a db.cursor context manager, we can assume that
there is a db user at this very moment.
This commit uses a single query to find databases that belongs to this
cursor user.

Also, this commit adds a message in the logs when an exception occurs
to facilitate debugging instead of silently returning an empty list.
2017-11-17 15:23:14 +01:00
Christophe Monniez 27128f2618 [FIX] db: remove usage of get_dsn_parameters
get_dsn_parameters may return in some edges cases (like on runbot)
and empty value for the user.
So it should not be used here, instead, a SQL query is able to provide
the currently connected user.
Also, get_dsn_parameters is new in psycopg 2.7.
2017-11-10 10:56:31 +01:00
Christophe Monniez b2a126da84 [IMP] server,db: coherently handle PGUSER env variable
When Odoo is started with a db_user using 'postgres', the process
exits with a status 1. However, this can be bypassed when the
PGUSER environment variable is used.
This commit will prevent the usage of the 'postgres' for the
environment variable too.
Also, when trying to list db's, various methods where used to find a
suitable postgres user to get this list.
In fact, as the db cursor is available, a user is already at work.
So, in order to avoid code duplication (e.g. verify user from
environment variables), this commit removes those various method
and get the db user from the cursor.
2017-11-09 13:25:16 +01:00
Fabien Meghazi 3af761b4f4 [FIX] db: do not log an error if access to pg_database is denied
Do not log a misleading "bad query" for cases where pg_database is not
accessible.
2017-10-03 19:14:42 +02:00
Olivier Dony b02dea7688 [IMP] config: allow blocking access to db manager
- The `--no-database-list` option will now also block access to database
  management functions and screens.
  Presumably this flag should only be used in production when all
  databases have been provisioned, so the admin should like to block
  access to the db manager at the same time.

- If no `--database` or `-d` parameter is provided, the system will be
  unable to fetch a list of databases at all, so users will be blocked
  with an error message.

- Hide the link on the login screen to the DB manager when it is
  disabled, to prevent sending users to an error page.

- Weak attempt at updating the documentation

Note: the security check for RPC methods could have been done in the RPC
dispatcher, however that would not have protected service methods when
called directly, e.g. by a controller (e.g. the dump method).
2017-10-03 12:46:03 +02:00
Olivier Dony 7d16769263 [IMP] config: support hashed master passwords
- Add support for hashed master passwords (super-admin password) using a
  strong scheme (PBKDF2_SHA512).

- Replace the password with a hash in memory (tools.config map), after
  verifying it

- Automatically replace the plaintext master password with a hash when
  saving it after a password change

- Preserve support for setting/using plaintext passwords when necessary
  (e.g. as a temporary deployment thing)
2017-10-03 12:45:22 +02:00
Christophe Simonis 5e0db55a2f [FIX][P3] core: correct database dump rpc function 2017-10-03 12:30:11 +02:00
Christophe Simonis 5ce21c7355 [MERGE] forward port branch saas-16 up to b3d0897f2d 2017-10-02 13:05:17 +02:00
Olivier Dony e4672db97d [IMP] module: make internal methods private
Only methods that are meant to be accessed by the client-side
directly (or via RPC) should be public. All others should be private by
default.
2017-09-28 14:15:30 +02:00
Christophe Simonis 3ac2a1106c [MERGE] forward port branch saas-15 up to ec15765eec 2017-09-11 13:30:03 +02:00
Christophe Simonis ec15765eec [MERGE] forward port branch saas-14 up to 48f88992da 2017-09-11 12:35:49 +02:00
Fabien Meghazi 6fa705399b [FIX] http/db: handle case when db_filter is empty in the config file
In such a case the db filtering won't be applied on an empty regex so
we use the list of databases passed to `db_name` (--database) as
the database list (and we also avoid to list all the databases present
on the postgresql cluster)

As a side effect, this patch allows to strengthen the postgresql security
by preventing Odoo to list all the databases present on the cluster.
2017-09-08 18:29:26 +02:00
Christophe Simonis 017ee5eab3 [MERGE] forward port branch saas-17 up to 877e709871 2017-08-24 13:17:53 +02:00
Xavier Morel 7dd062f835 [FIX] P3: text model types
* remove references to basestring & unicode (use relevant pycompat
  helpers)
* remove some str calls (either entirely or replaced by relevant
  helper, either text or native)
* use better API to avoid unnecessary conversions
* remove some XML declarations in views
2017-08-20 23:25:54 +02:00
Xavier Morel 3824b5dcc1 [FIX] P3: fix base64 and StringIO uses
* StringIO removed from stdlib, replace with io
* try to correctly handle BytesIO/StringIO (one is for bytes the other
  is for text)
* fix base64: Python 3 removed bytes-encoding and bytes-bytes
  codecs (via #encode) so replace all calls to str.encode('base64'),
  also b64encode is a bytes->bytes conversion so attempt to properly
  handle that

issue #8530
2017-08-20 23:25:54 +02:00
Fabien Meghazi b34e00540e [IMP] http/db: change behaviour of list_dbs() when --db-filter is not provided (Closed #18526)
In case `--db-filter` is not provided and `--database` is passed,
Odoo will not fetch the list of databases available in the postgres
server anymore because it does not have anything to match against this
list. Instead, `list_dbs()` will use the value of `--database` as a
comma separated list of exposed databases.

This allows better security hardening in postgres access rights.

Basically, that means that those commands

    $ odoo-bin -d foobar
    $ odoo-bin -d foo,bar,baz

are now respectively equivalent to those commands

    $ odoo-bin -d foobar --db-filter='^foobar$'
    $ odoo-bin -d foo,bar,baz --db-filter='^(foo|bar|baz)$'

The old behaviour can still be used with this command:

    $ odoo-bin -d foobar --db-filter='.*'
2017-08-03 13:49:51 +02:00
Xavier Morel 6ad587dc8f [FIX] db restoration existence check
5ee9ec7d removed bool(Connection), turns out db restore still used it
but muted the logger so that was hard to notice in the logs.
2017-06-28 10:05:33 +02:00
Xavier Morel b897dcde15 [FIX] P3: import pattern which doesn't seem to work right
``import odoo.addons.foo as bar`` doesn't seem to properly trigger the
import hook in Python 3 (it blows up on decimal_precision and
base). Thus convert *all* examples of that pattern to the more
sensible ``from odoo.addons import foo as bar``.
2017-05-22 13:30:50 +02:00
xmo-odoo fffaf735f5 [FIX] P3: list -> iterable builtins (#16811)
In Python 3:

* various builtins and dict methods were changed to return
  view/iterable objects rather than lists
* and the separate Python 2 view/iterable builtins and methods were
  removed altogether

This is problematic when using these items as list (which the happens
repeatedly in Odoo), but more viciously when iterating *multiple times*
over them (which also happens, which I've messed up multiple times while
writing this, and which is a pain to debug even when you've just created
the issue).

Convert all code using these to semantics-matching cross-version
helper functions to get the LCD behaviour between P2 and P3, and
forbid the builtins via lint.

issue #8530
2017-05-10 09:39:55 +02:00
Xavier Morel 3979f6802e [#8530] convert exception handlers to except..as syntax
Futurize fixers:
* lib2to3.fixes.fix_except
2017-04-11 14:53:29 +02:00