[7.0] dump/restore cannot get db password from config file

Bug #1149484 reported by Pavel Batishchev
24
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Confirmed
Medium
OpenERP's Framework R&D

Bug Description

There is code in lib/python2.7/site-packages/openerp-7.0-py2.7.egg/openerp/service/web_services.py:
    @contextlib.contextmanager
    def _set_pg_password_in_environment(self):
        """ On Win32, pg_dump (and pg_restore) require that
        :envvar:`PGPASSWORD` be set

        This context management method handles setting
        :envvar:`PGPASSWORD` iif win32 and the envvar is not already
        set, and removing it afterwards.
        """
        if os.name != 'nt' or os.environ.get('PGPASSWORD'):
            yield
        else:
            os.environ['PGPASSWORD'] = tools.config['db_password']
            try:
                yield
            finally:
                del os.environ['PGPASSWORD']

So, on linux machine it does not read db_password from config, and dump/restore gives you Access Denied. Possible solution is to create .pgpass file, but should not it work just with db_password in config?

Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Bob Muller (lp23) wrote :
Download full text (3.1 KiB)

Latest version in trunk (r4854) gives this error when doing a restore:

2013-04-16 04:20:13,258 16812 ERROR None openerp.netsvc: _set_pg_password_in_environment() takes exactly 1 argument (0 given)
Traceback (most recent call last):
  File "/home/openerp7/trunk/server/openerp/netsvc.py", line 237, in dispatch_rpc
    result = dispatch(method, params)
  File "/home/openerp7/trunk/server/openerp/service/db.py", line 80, in dispatch
    return fn(*params)
  File "/home/openerp7/trunk/server/openerp/service/db.py", line 253, in exp_restore
    with _set_pg_password_in_environment():
  File "/usr/lib/python2.7/contextlib.py", line 84, in helper
    return GeneratorContextManager(func(*args, **kwds))
TypeError: _set_pg_password_in_environment() takes exactly 1 argument (0 given)
2013-04-16 04:20:13,259 16812 ERROR None openerp.addons.web.http: An exception occured during an http request
Traceback (most recent call last):
  File "/home/openerp7/trunk/web/addons/web/http.py", line 296, in dispatch
    r = method(self, **self.params)
  File "/home/openerp7/trunk/web/addons/web/controllers/main.py", line 818, in restore
    req.session.proxy("db").restore(restore_pwd, new_db, data)
  File "/home/openerp7/trunk/web/addons/web/session.py", line 30, in proxy_method
    result = self.session.send(self.service_name, method, *args)
  File "/home/openerp7/trunk/web/addons/web/session.py", line 88, in send
    return openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "/home/openerp7/trunk/server/openerp/netsvc.py", line 237, in dispatch_rpc
    result = dispatch(method, params)
  File "/home/openerp7/trunk/server/openerp/service/db.py", line 80, in dispatch
    return fn(*params)
  File "/home/openerp7/trunk/server/openerp/service/db.py", line 253, in exp_restore
    with _set_pg_password_in_environment():
  File "/usr/lib/python2.7/contextlib.py", line 84, in helper
    return GeneratorContextManager(func(*args, **kwds))
TypeError: _set_pg_password_in_environment() takes exactly 1 argument (0 given)

After some investigation I found that the contextmanager broke after refactoring, however the following patch might fix this bug (at least I was able to restore databases again):

=== modified file 'openerp/service/db.py'
--- openerp/service/db.py 2013-04-04 13:07:04 +0000
+++ openerp/service/db.py 2013-04-16 04:40:40 +0000
@@ -197,7 +197,7 @@
     return True

 @contextlib.contextmanager
-def _set_pg_password_in_environment(self):
+def _set_pg_password_in_environment(self=None):
     """ On systems where pg_restore/pg_dump require an explicit
     password (i.e. when not connecting via unix sockets, and most
     importantly on Windows), it is necessary to pass the PG user
@@ -213,10 +213,10 @@
          SaaS (giving SaaS users the super-admin password is not a good idea
          anyway)
     """
- if os.environ.get('PGPASSWORD') or not tools.config['db_password']:
+ if os.environ.get('PGPASSWORD') or not openerp.tools.config['db_password']:
         yield
     else:
- os.environ['PGPASSWORD'] = tools.config['db_password']
+ os.environ['PGPASSWORD'] = openerp.tools.config['db_password']
         try:
             yield
         ...

Read more...

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.