anybox.recipe.odoo icon indicating copy to clipboard operation
anybox.recipe.odoo copied to clipboard

python_odoo script connects to all databases

Open sbidoul opened this issue 10 years ago • 8 comments

Not sure if this is an issue or merely a question.

When using the python_odoo script generated by the recipe, it seems it connects to all available databases. This seems to be the normal Odoo behaviour, but unncessarily uses up postgres connections.

However, when using a script, we connect using session.open(db=DATABASE_NAME) and typically want to work on one database only.

Is there an easy way to make sure the script connects to only one database?

sbidoul avatar Dec 11 '14 17:12 sbidoul

It is my understanding that when you start python_odoo you don't connect to any database until you connect to one using session.open(db_name). Personally, I find that step annoying, so I run (and keep an alias):

python_odoo -i -c "session.open($db_name)"

Which gives me a shell after opening a session.

bwrsandman avatar Dec 11 '14 18:12 bwrsandman

As soon as I connect using session.open(db=...) I see logs about the db I connect to, but also some logs about other databases.

sbidoul avatar Dec 11 '14 22:12 sbidoul

@bwrsandman you're right. And I understand that you may find this annoying, but it's somewhat necessary to keep a high level of generality, as it allows:

  • scripts to decide exactly which database to open and when (maybe after prompting the user)
  • not to open any database : it may be useful for quick introspection to import the general API and for that, a quick startup time is also appreciable.

About scripts, the preferred way to make some is in my mind to provide them in regular setuptools distributions and register them as openerp_scripts, but some might righteously find this too heavy.

@sbidoul I confirm that this is not expected, can you be a bit more specific about how to reproduce and/or see it ? I'm not sure much can be done, though, because the Session class does not much more than perform some calls from the openerp python package. In any case I'll need precise version of the recipe and of Odoo

gracinet avatar Dec 12 '14 15:12 gracinet

@gracinet don't get me wrong, I am not complaining about the design. It makes a lot of sense to me. My process involves calling python_odoo followed with session.open(db_name) in the console. The annoying bit is cycling through the history and typing the same thing to work on db_name.

Hense the alias python_odoo -i -c "session.open($db_name)" is always in my history and I can skip the step.

tl;dr: Protip: python_odoo -i -c "session.open($db_name)" saves me a step, there is no problem with the current implementation.

bwrsandman avatar Dec 12 '14 15:12 bwrsandman

@bwrsandman no worries, I was just putting a bit of context :-)

Sometimes I'd just change the /etc/odoo.cfg just to call the simpler session.open() from the shell, but your way of doing does it all.

Cheers

gracinet avatar Dec 12 '14 15:12 gracinet

@sbidoul do you still see unexpected databases in your log ? If so, any hints for reproduction ?

gracinet avatar Jan 17 '15 15:01 gracinet

Yes I do. I've not had time to investigate yet, but it seems it shows database that are not completely installed. Nothing urgent in any case.

sbidoul avatar Jan 17 '15 15:01 sbidoul

ok, I'll carry on triaging / merging / fixing the other issues, then, thanks.

gracinet avatar Jan 17 '15 15:01 gracinet