lefilament/ansible_role_odoo_docker

Database odoo not initialized, you can force it with `-i base`

nqb opened this issue · 3 comments

nqb commented

Hello,

After my Docker services have been started by handlers and with Traefik fix mentioned on docker role, I got a 500 error when I tried to reach my Odoo instance.

If I run a docker logs odoo, I see following messages:

2021-03-12 00:47:17,366 1 INFO ? odoo: Odoo version 12.0 
2021-03-12 00:47:17,367 1 INFO ? odoo: Using configuration file at /opt/odoo/etc/odoo.conf 
2021-03-12 00:47:17,367 1 INFO ? odoo: addons paths: ['/opt/odoo/data/addons/12.0', '/opt/odoo/odoo/addons', '/opt/odoo/additional_addons', '/opt/odoo/private_addons', '/opt/odoo/odoo/odoo/addons'] 
2021-03-12 00:47:17,368 1 INFO ? odoo: database: odoo@db:5432 
2021-03-12 00:47:17,463 1 INFO ? odoo.addons.base.models.ir_actions_report: Will use the Wkhtmltopdf binary at /usr/local/bin/wkhtmltopdf 
2021-03-12 00:47:17,640 1 INFO ? odoo.service.server: HTTP service (werkzeug) running on 7f08b1d3750c:8069 
2021-03-12 00:47:17,649 1 ERROR ? odoo.modules.loading: Database odoo not initialized, you can force it with `-i base` 
2021-03-12 00:48:17,704 1 ERROR odoo odoo.sql_db: bad query: SELECT latest_version FROM ir_module_module WHERE name='base'
ERROR: relation "ir_module_module" does not exist
LINE 1: SELECT latest_version FROM ir_module_module WHERE name='base...

I found an old Odoo issue related to that issue and I was able to workaround issue with following patch as described by a maintainer:

diff --git a/templates/prod.yaml.j2 b/templates/prod.yaml.j2
index 0db431f..baa339b 100644
--- a/templates/prod.yaml.j2
+++ b/templates/prod.yaml.j2
@@ -50,6 +50,7 @@ services:
         image: postgres:{{ odoo_db_version }}-alpine
         container_name: odoo_db
         environment:
+            POSTGRES_DB: postgres
             POSTGRES_USER: "{{ odoo_prod.db_user }}"
             POSTGRES_PASSWORD: "{{ odoo_prod.db_pass }}"
         labels:
diff --git a/templates/test.yaml.j2 b/templates/test.yaml.j2
index 0228dcb..3c5a353 100644
--- a/templates/test.yaml.j2
+++ b/templates/test.yaml.j2
@@ -51,6 +51,7 @@ services:
         image: postgres:{{ odoo_db_version }}-alpine
         container_name: {{ item.dir }}_db
         environment:
+            POSTGRES_DB: postgres
             POSTGRES_USER: "{{ item.db_user }}"
             POSTGRES_PASSWORD: "{{ item.db_pass }}"
         labels:

How did you solve that issue on your side ?

Thank you for reporting it @nqb
We have also observed that from time to time, the order of initialization of database when starting Odoo the first time was not properly followed leading to the issue you describe above (database not properly initialized).
The workaround we have been using so far was to stop containers and remove volumes (docker-compose down -v) and recreate containers again (docker-compose up -d).

As far as I remember this occured only on prod docker, not on nonprod ones, not sure why exactly...

I do not think that your solution should fix it, since it would initialize a postgres database when starting odoo_db but the problem is not with that one but rather with the one that Odoo will create/use ({{ odoo_prod.db }})

nqb commented

Hello,

In issue mentioned previously, I missed to provide a link to Odoo maintainer comment.

If I look at usage instructions of official Odoo docker images, they use POSTGRES_DB=postgres with postgres:10 image.

EDIT: on my side, it seems to work.

Thanks, if everyone agrees that this solves the issue, fine with me :)
I fixed it with 88eeeae