Coder Social home page Coder Social logo

Comments (16)

sebalix avatar sebalix commented on September 15, 2024

Hi,

The first error (KeyError: '2/db') is normal, OERPLib try to guess the server version by checking differents XML-RPC URLs. You can avoid that by providing explicitly the version used:

oerp = oerplib.OERP([...], version='7.0')

Regarding the OperationalError: FATAL: no existe la base de datos <<testcompany>>, I have never seen that.

Finally the warnings related to res.users.user_email, this is due to the login step, OERPLib will instantiate a browse_record for the user currently logged, and by doing this it reads all fields of the user record (a call to the read() method without specify the fields to read). When Odoo/OpenERP will remove this field, the warning will disappear as well. It is displayed three times surely because you perform 3 login, or a similar operation.

Regards,

from oerplib.

dbareiro avatar dbareiro commented on September 15, 2024

Hi Sébastien.

Thanks for responding.

Effectively, after specifying the version of OpenERP, the '2/db' error no longer appears. Thanks for that.

Regarding OperationalError: FATAL: no existe la base de datos <<testcompany>>, this is an error message in spanish (I guess because the environment is in spanish). It basically says that there is no <<testcompany>> database. Testcompany is the name of the database to create for this instance.

I guess this may have to do with the error that appears slightly above (openerp.sql_db: Connection to the database failed):

2015-02-21 15:57:21,258 6438 INFO ? openerp: OpenERP version 7.0 
2015-02-21 15:57:21,261 6438 INFO ? openerp: addons paths: /opt/odoo/testcompany/addons 
2015-02-21 15:57:21,264 6438 INFO ? openerp: database hostname: 10.1.0.41 
2015-02-21 15:57:21,264 6438 INFO ? openerp: database port: 5432 
2015-02-21 15:57:21,264 6438 INFO ? openerp: database user: testcompany 
2015-02-21 15:57:22,507 6438 INFO ? openerp.addons.google_docs.google_docs: GData lib version `%s GData-Python/2.0.17` detected 
2015-02-21 15:57:24,737 6438 INFO ? openerp: OpenERP server is running, waiting for connections... 
2015-02-21 15:57:24,767 6438 INFO ? openerp.service.wsgi_server: HTTP service (werkzeug) running on 0.0.0.0:8070 
2015-02-21 15:57:30,128 6438 WARNING ? openerp.sql_db: __nonzero__() is deprecated. (It is too expensive to test a connection.) 
2015-02-21 15:57:30,179 6438 ERROR ? openerp.sql_db: Connection to the database failed 
Traceback (most recent call last): 
  File "/opt/odoo/testcompany/openerp/sql_db.py", line 442, in borrow 
    result = psycopg2.connect(dsn=dsn, connection_factory=PsycoConnection) 
  File "/usr/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, in connect 
    connection_factory=connection_factory, async=async) 
OperationalError: FATAL:  no existe la base de datos <<testcompany>> 

2015-02-21 15:57:30,184 6438 INFO ? werkzeug: 127.0.0.1 - - [21/Feb/2015 15:57:30] "POST /openerp/xmlrpc/1/db HTTP/1.1" 200 - 
2015-02-21 15:57:30,193 6438 INFO ? openerp.service.web_services: Create database `testcompany`.
[...]

It is not clear to me why OpenERP attempt to verify the existence of the database and even connect, since at that time I am wanting to create it.

Below I paste the code I'm using. Maybe this can help to indentify the cause of the error and warnings.

# Prepare the connection to the server
oerp = oerplib.OERP('localhost', protocol='xmlrpc', port=instance_port, version=oerp_version)


result = oerp.db.db_exist(dbname)

if not result:
        oerp.db.create_database(superadmin_pwd, dbname, demo_data, language, admin_pwd)

        ### Enable Technical Features ###
        oerp.login('admin', admin_pwd, dbname)

        data_model = oerp.get('ir.model.data')
        user_model = oerp.get('res.users')

        oerp.config['auto_context'] = False
        res_model, res_id = data_model.get_object_reference('base', 'group_no_one')
        oerp.config['auto_context'] = True

        user = user_model.browse(1)
        user.groups_id += res_id
        oerp.write_record(user)
        ### Enable Technical Features ###

        sys.exit(0)
else:
        print "Database exists"
        sys.exit(1)

Thanks again and best regards,

Daniel

from oerplib.

sebalix avatar sebalix commented on September 15, 2024

This is surely the db_exist method, if we check its implementation on OpenERP 7:

def exp_db_exist(self, db_name):
    ## Not True: in fact, check if connection to database is possible. The database may exists
    return bool(sql_db.db_connect(db_name))

The sql_db.db_connect() call is raising the error I think.

A workaround in your script could be:

if dbname not in oerp.db.list():
    [...]

But the db.list() method does not list hidden databases (if you have configured the db_filter option in the server configuration file).

from oerplib.

dbareiro avatar dbareiro commented on September 15, 2024

Hi Sébastien.

Thanks for your reply.

I was using oerp.db.db_exist(dbname), which was something you had suggested me an previous issue (question), because I was using a startup script that used --no-database-list in DAEMON_OPTS. This was necessary because the instance could use more than one database. But as I am now using a single database, I removed that parameter on the startup script and I did the existence check of the database in the way you suggested now. Thanks for that.

Regarding to the three warnings mentioned (which do not appear in OpenERP 8.0/Odoo):

2015-02-22 11:34:43,813 9500 WARNING testcompany openerp.osv.orm: Field res.users.user_email is deprecated: Use the email field instead of user_email. This field will be removed with OpenERP 7.1.

Do you think it could make changes to the script to prevent that these warnings be displayed?

Best regards,
Daniel

from oerplib.

sebalix avatar sebalix commented on September 15, 2024

There is nothing we can do from OERPLib about that. The error raised on db_exist() is all about the way OpenERP checks the database, but excepting an ERROR message in your logs, there is no problem.

About the warnings, the first one is generated by the OERP.login() method which returns a user browse record: https://github.com/osiell/oerplib/blob/master/oerplib/oerp.py#L195-L223
The call to browse() reads all standard fields, including user_email, so a warning is triggered on OpenERP. But there is no problem about that, if you don't make use of this field in your code (as it is deprecated, it should be a bad idea to use it), and we can't change the API of the OERP.login() method just for a warning which is not present with Odoo >= 8.0.

Another warning is due to your code here for the exact same reasons:

user = user_model.browse(1)
user.groups_id += res_id
oerp.write_record(user)

If really this warning is boring you, just rewrite this piece of code like this:

user_model.write([1], {'groups_id': [(4, res_id)]})    # (4, ID) means in OpenERP "add ID to groups_id"

See : https://github.com/odoo/odoo/blob/8.0/openerp/osv/fields.py#L1470-L1476

Regards,

from oerplib.

dbareiro avatar dbareiro commented on September 15, 2024

Hi Sébastien.

Thanks for your reply, the explanations and references.

Regarding db_exist(), no problem. I already changed it for your previous suggestion of using oerp.db.list().

I changed the code block you mentioned to avoid some warnings. Thus, although we can not avoid the warnings generated in the login, the log is at least a little cleaner.

Regarding user_email (as it is deprecated, it should be a bad idea to to use it), there is another script which changes the data of the company:

## Set company parameters ###
company_model = oerp.get('res.company')
company = company_model.browse(1)

country_model = oerp.get('res.country')
country_id = country_model.search([('name', '=', country)])[0]

company.country_id = country_id

company.name = name
company.rml_header1 = tagline
company.email = email
company.phone = phone

company.street = street
company.city = city
company.zip = zip
company.website = website

on_change(oerp, company, 'on_change_country', [company.id], country_id)

oerp.write_record(company)
### Set company parameters ###

Do you think that modify the company.email field could bring a problem with OpenERP 7? I do not see the email field in res_company table, so I sense that it will come from a relationship with another table (maybe res_partner?).

Best regards,
Daniel

from oerplib.

sebalix avatar sebalix commented on September 15, 2024

This is exactly that, the email field comes from the related partner of the company. No problem to change it.

from oerplib.

dbareiro avatar dbareiro commented on September 15, 2024

Perfect, Sébastien.

I thank you very much for your time and assistance to analyze what consulted on this issue.

Best regards,
Daniel

from oerplib.

dbareiro avatar dbareiro commented on September 15, 2024

Hi, Sébastien.

A question about the passage of the version on oerp = oerplib.OERP([...], version=...) to avoid the KeyError: '2 / db' when using OpenERP 7.0.

I have several instances, some with Odoo 8.0 and others with OpenERP 7.0. Is there any way to recognize the version in an instance that is already running for specify explicitly it so that OERPLib can avoid this error?

I had thought something like this:

RELEASE_FILE = '/opt/odoo/' + INSTANCE_NAME + '/openerp/release.py'

if os.path.isfile(RELEASE_FILE):
        inFile = open(RELEASE_FILE, "r")

        for line in inFile:
                if line.startswith("version_info"):
                        VERSION_LIST = line.split("=")[1].strip()
                        VERSION = VERSION_LIST.split(",")[0].replace("(","") + '.0'
        inFile.close

        print VERSION
else:
        print "Instance not found"
        sys.exit(2)

But maybe there is a more elegant way to do it.

Thanks in advance.

Best regards,
Daniel

from oerplib.

sebalix avatar sebalix commented on September 15, 2024

There is no proper way to do what you want.
This is the price to paid for supporting OpenERP from the version 5 ;) By dropping the support of this version (and maybe the 6.0 and 6.1 too), we could avoid this check on different XML-RPC URL to guess the version, but the purpose of OERPLib is to support a maximum of versions precisely (and it's a life-saver for us at OSIELL).

from oerplib.

dbareiro avatar dbareiro commented on September 15, 2024

Hola, Sébastien.

Thanks for your reply. I understand that this is the price to pay :) I think I'll use the workaround that I was telling you about. It's not the most elegant, but it serves to identify the version for OERPLib not raise this exception.

I'm also seeing that using oerp.db.restore on OpenERP 7 I'm having the same exception caused by the db_exist method on OpenERP 7:

2015-03-12 12:37:01,858 762 INFO ? werkzeug: 127.0.0.1 - - [12/Mar/2015 12:37:01] "POST /xmlrpc/2/db HTTP/1.1" 200 - 
2015-03-12 12:37:01,864 762 INFO ? werkzeug: 127.0.0.1 - - [12/Mar/2015 12:37:01] "POST /openerp/xmlrpc/1/db HTTP/1.1" 200 - 
2015-03-12 12:37:01,979 762 WARNING ? openerp.sql_db: __nonzero__() is deprecated. (It is too expensive to test a connection.) 
2015-03-12 12:37:02,028 762 ERROR ? openerp.sql_db: Connection to the database failed 
Traceback (most recent call last): 
  File "/opt/odoo/testcompany/openerp/sql_db.py", line 442, in borrow 
    result = psycopg2.connect(dsn=dsn, connection_factory=PsycoConnection) 
  File "/usr/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, in connect 
    connection_factory=connection_factory, async=async) 
OperationalError: FATAL:  no existe la base de datos <<testcompany>> 
2015-03-12 12:37:20,691 762 INFO ? openerp.service.web_services.db.restore: RESTORE DB: testcompany 
2015-03-12 12:37:20,692 762 INFO ? werkzeug: 127.0.0.1 - - [12/Mar/2015 12:37:20] "POST /openerp/xmlrpc/1/db HTTP/1.1" 200 -

Do you think here we could use some workaround to avoid this error?

Moreover, not sure if you are aware, but a few days ago, looking for other things, I found the pleasant surprise to see that OERPLib has been included in Debian Sid and Debian Jessie so I wanted to take to congratulate you for this important achievement for the effort, dedication and work you have put into its development

Best regards,
Daniel

from oerplib.

sebalix avatar sebalix commented on September 15, 2024

Hi,

Yes, there is an error because OpenERP uses the db_exist function inside the restore one. See : https://github.com/odoo/odoo/blob/7.0/openerp/service/web_services.py#L294 (there is a call to self.exp_db_exist(db_name) on the first lines)

A workaround could be to create an empty database on PostgreSQL ($ createdb -E unicode db_name -O oerp_pg_user) before running the OERPLib code making the restore operation. Not very convenient if you are running your OERPLib script remotely.

About the package in Debian yes, special thanks to W. Martin Bolgert! (a Debian developer and OERPLib user), it's a great news.

from oerplib.

dbareiro avatar dbareiro commented on September 15, 2024

Hi, Sébastien.

Thanks for the observations on the use of the db_exist function on restore and the suggested workaround.

And congratulations again for the integration of OERPLib in Debian! :)

Best regards,
Daniel

from oerplib.

dbareiro avatar dbareiro commented on September 15, 2024

Hi, Sébastien.

I tried the workaround you had suggested, but still it is giving an error but now saying that the database already exists :-/

2015-03-25 13:40:10,680 4409 WARNING ? openerp.sql_db: __nonzero__() is deprecated. (It is too expensive to test a connection.) 
2015-03-25 13:40:10,732 4409 WARNING ? openerp.service.web_services.db.restore: RESTORE DB: testcompany already exists 
2015-03-25 13:40:10,736 4409 ERROR ? openerp.netsvc: Database already exists 
Traceback (most recent call last): 
  File "/opt/odoo/testcompany/openerp/netsvc.py", line 296, in dispatch_rpc 
    result = ExportService.getService(service_name).dispatch(method, params) 
  File "/opt/odoo/testcompany/openerp/service/web_services.py", line 140, in dispatch 
    return fn(*params) 
  File "/opt/odoo/testcompany/openerp/service/web_services.py", line 299, in exp_restore 
    raise Exception, "Database already exists" 
Exception: Database already exists 
2015-03-25 13:40:10,740 4409 INFO ? werkzeug: 127.0.0.1 - - [25/Mar/2015 13:40:10] "POST /openerp/xmlrpc/1/db HTTP/1.1" 200 -

It seems there is no way to avoid this. Or do you think there may be another workaround?

Best regards,
Daniel

from oerplib.

sebalix avatar sebalix commented on September 15, 2024

Hi,

I think you can't do anything about it. In general, OpenERP raises exceptions even to inform the user on the UI that something got wrong on a predictable process (to popup a warning message on the web interface).

You can open a bug report about the restore RPC method, but it will be closed because it implies to change the behaviour (API change are refused I think).

from oerplib.

dbareiro avatar dbareiro commented on September 15, 2024

Hi, Sébastien.

Yes, I figured we could not do anything about it. Anyway I thank you very much for responding.

Best regards,
Daniel

from oerplib.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.