Skip to Content

Contributors

Technical Question: Restart Odoo process after res.partner model change

Hello Odoo contributors,

I am developing, deploying and fixing Odoo for a while and there is one 
issue I haven't bothered enough to come up with a proper solution or 
strategy.

The problem is simple: I have an Odoo instance running with a module 
that extends the res.partner model. The res.partner code of this module 
is updated with a new field. The Odoo server is restarted and exits with 
a "column does not exist" error.

The same procedure works for modules that extend other models than 
res.partner or res.user. As I understand the res.partner (and other) 
tables are queried when the Odoo process starts. The SQL queries fail, 
because the model code does not match the database schema.

The solution to the problem seems obvious, before starting the Odoo 
server with the new code you install module (odoo-bin -i ...). However, 
automating this step in a deployment pipeline is difficult as you don't 
know which module needs to be updated. Always updating the base module 
seems like an overkill.

Do you know this problem? Have you solved this problem?

I would be glad to hear from you.

Regards,

Janik

Here is a guide to reproduce the issue with https://odoo.build/:

1. Init a new datbase and start the Odoo server: `task start db; task 
init-db; task start native`

2. Install the contacts module: `task install-module contacts`

3. Stop the Odoo process.

4. Add a new field to the res.partner code: `vi 
odoo/odoo/addons/base/models/res_partner.py`

```python

xy = fields.Char()

```

5. Start the Odoo server: `task start native`

It fails with:

```

...

psycopg2.errors.UndefinedColumn: column res_partner.xy does not exist
LINE 1: ..."message_bounce", "res_partner"."name" AS "name", "res_partn...
```                                                        ^


-- 
We are hiring: https://www.mint-system.ch/jobs
Send application to: jobs@mint-system.ch

CTO Mint System GmbH
Tel: +41 44 244 7222


by Janik von Rotz - 05:22 - 20 Jun 2024

Follow-Ups

  • Re: Technical Question: Restart Odoo process after res.partner model change

    Hi Janik,

    On 6/21/24 14:02, Janik von Rotz wrote:
    A simple solution is probably a fixed list of modules that should always 
    be updated (from the cli) after the code change and before restarting 
    the Odoo container.
    

    This is indeed the more crude solution that we generally use for our clients - either figure out by hand which modules to update if you're in a hurry, or just `-u base`.

    But the two solutions mentioned are smarter in that sense because they figure out from the code change what to update.

    Cheers


    by Tom Blauwendraat - 02:31 - 21 Jun 2024
  • Re: Technical Question: Restart Odoo process after res.partner model change
    Hi Pedro,
    
    Thanks for your reply.
    
    Yes exactly, access to res.partner/res.user is done before I can act. 
    Updating the module with the cli works (but you have to know the module 
    name). As I understand click-odoo-update works similar to 
    module_auto_update, but can update all changed modules from a separate 
    Odoo process.
    
    A simple solution is probably a fixed list of modules that should always 
    be updated (from the cli) after the code change and before restarting 
    the Odoo container.
    
    Regards, Janik
    
    On 6/21/24 11:52, Pedro M. Baeza wrote:
    
    > Maybe the problem is that you want to update from the UI, and in that 
    
    > case, an access to res.partner/res.users is done before you can act. 
    
    > You should do it in the command line with the -u argument (or 
    
    > click-odoo-update), or with a parallel run (in Docker environments), 
    
    > or similar.
    
    >
    
    > Regards.
    
    >
    
    > _______________________________________________
    
    > Mailing-List: https://odoo-community.org/groups/contributors-15
    
    > Post to: mailto:contributors@odoo-community.org
    
    > Unsubscribe: https://odoo-community.org/groups?unsubscribe
    
    >
    
    -- 
    We are hiring: https://www.mint-system.ch/jobs
    Send application to: jobs@mint-system.ch
    
    CTO Mint System GmbH
    Tel: +41 44 244 7222
    
    

    by Janik von Rotz - 02:01 - 21 Jun 2024
  • Re: Technical Question: Restart Odoo process after res.partner model change
    Maybe the problem is that you want to update from the UI, and in that case, an access to res.partner/res.users is done before you can act. You should do it in the command line with the -u argument (or click-odoo-update), or with a parallel run (in Docker environments), or similar.

    Regards.

    by Pedro M. Baeza - 11:51 - 21 Jun 2024
  • Re: Technical Question: Restart Odoo process after res.partner model change
    Do you define the database in the command with -d <database_name> beside the -u argument? 
    I had some effects when the -d was missing. 

    Von: Janik von Rotz <notifications@odoo-community.org>
    Gesendet: Friday, June 21, 2024 8:50:04 AM
    An: Contributors <contributors@odoo-community.org>
    Betreff: Re: Technical Question: Restart Odoo process after res.partner model change
     

    ACHTUNG! Diese E-Mail stammt von außerhalb der Organisation. Klicken Sie nicht auf Links und öffnen Sie keine Anhänge, es sei denn, Sie kennen den Absender und wissen, dass der Inhalt sicher ist.

    Hi Graeme,

    there is no own code so there is no bug. I am pretty sure what I described is reproducible with any Odoo setup.

    As I understand updating the database schema for a running Odoo process without restarting the process is simply not possible.

    I assume Odoo has an internal state of the field defined in the module code. Only if the process is restarted the state is updated.

    Regards,

    Janik

    On 6/20/24 22:02, Graeme Gellatly wrote:
    Then that is a bug in your own code, or you have not also restarted another running odoo process with the old info. -u has worked forever.

    On Fri, Jun 21, 2024 at 6:45 AM Janik von Rotz <notifications@odoo-community.org> wrote:

    Hi Tom

    Thanks for the reply.

    I did another test with the same results.

    The Odoo log tells that it updated the tables for the module, but it didn't.

    Cheers,

    Janik


    Init Odoo database with the required modules:

    ```
    task start
    docker-odoo-install -d 16.0 -i partner_fax,contacts,module_auto_update
    ```

    Then clicked *Apps > Auto-Upgrade Modules*.

    Getting the hash for `partner_fax`: `d1db56b45a4c5baa9a6cb0c571c37b0c394d8840`

    Then changing the file:

    ```
    cd oca/partner-contact
    vi partner_fax/models/res_partner.py
    ```

    By adding:

    ```python
    xy = fields.Char()
    ```

    Then clicked *Apps > Auto-Upgrade Modules*.

    The Odoo log:

    ```
    2024-06-20 18:32:03,665 1 INFO 16.0 odoo.modules.registry: module partner_fax: creating or updating database tables
    ```

    Getting the hash for `partner_fax`: `b8236a3734e752fa62b669674afaa1db750f031d`

    When doing a restart.

    ```
    task restart
    ```

    I still get this message:

    ```
    psycopg2.errors.UndefinedColumn: column res_partner.xy does not exist
    LINE 1: ...e" AS "write_date", "res_partner"."fax" AS "fax", "res_partn...
                                                                 ^
    ```

    The issue can be resolved by installing the module:

    ```
    docker-odoo-install -d 16.0 -i partner_fax  
    ```

    On 6/20/24 19:57, Tom Blauwendraat wrote:
    Hi Janik

    -i is wrong anyway, it installs, -u is what you need

    I dont know why the field update does not trigger, it should - did you restart odoo beforehand?

    20 jun. 2024 18:58:18 Janik von Rotz <notifications@odoo-community.org>:

    Hi Tom

    I tested this module and like it! However, it seems its only doing an update and not an install, which does not update the database schema.

    Cheers, Janik

    Here is how I tested the module with https://odoo.build/:

    Init Odoo database with the required modules.

    ```
    task start
    docker-odoo-install -d 16.0 -i partner_fax,contacts,module_auto_update
    ```

    Checking the hash: `"partner_fax": "b8236a3734e752fa62b669674afaa1db750f031d"`

    Then changing a module file.

    ```
    vi oca/partner-contact/partner_fax/models/res_partner.py
    ```

    Adding:

    ```python
    xy = fields.Char()
    ```

    Then clicked *Apps > Auto-Upgrade Modules*.

    When doing a restart.

    ```
    task restart
    ```

    I still get this message:

    ```
    psycopg2.errors.UndefinedColumn: column res_partner.xy does not exist
    LINE 1: ...e" AS "write_date", "res_partner"."fax" AS "fax", "res_partn...
                                                                 ^
    ```

    Resolving the issue by installing the module:

    ```

    docker-odoo-install -d 16.0 -i partner_fax
    ```

    On 6/20/24 17:42, Tom Blauwendraat wrote:
    module_auto_update

    20 jun. 2024 17:22:17 Janik von Rotz <notifications@odoo-community.org>:

    Hello Odoo contributors,
    
    I am developing, deploying and fixing Odoo for a while and there is one 
    issue I haven't bothered enough to come up with a proper solution or 
    strategy.
    
    The problem is simple: I have an Odoo instance running with a module 
    that extends the res.partner model. The res.partner code of this module 
    is updated with a new field. The Odoo server is restarted and exits with 
    a "column does not exist" error.
    
    The same procedure works for modules that extend other models than 
    res.partner or res.user. As I understand the res.partner (and other) 
    tables are queried when the Odoo process starts. The SQL queries fail, 
    because the model code does not match the database schema.
    
    The solution to the problem seems obvious, before starting the Odoo 
    server with the new code you install module (odoo-bin -i ...). However, 
    automating this step in a deployment pipeline is difficult as you don't 
    know which module needs to be updated. Always updating the base module 
    seems like an overkill.
    
    Do you know this problem? Have you solved this problem?
    
    I would be glad to hear from you.
    
    Regards,
    
    Janik
    
    Here is a guide to reproduce the issue with https://odoo.build/:
    
    1. Init a new datbase and start the Odoo server: `task start db; task 
    init-db; task start native`
    
    2. Install the contacts module: `task install-module contacts`
    
    3. Stop the Odoo process.
    
    4. Add a new field to the res.partner code: `vi 
    odoo/odoo/addons/base/models/res_partner.py`
    
    ```python
    
    xy = fields.Char()
    
    ```
    
    5. Start the Odoo server: `task start native`
    
    It fails with:
    
    ```
    
    ...
    
    psycopg2.errors.UndefinedColumn: column res_partner.xy does not exist
    LINE 1: ..."message_bounce", "res_partner"."name" AS "name", "res_partn...
    ```                                                        ^
    
    
    
    -- 
    We are hiring: https://www.mint-system.ch/jobs
    Send application to: jobs@mint-system.ch
    
    CTO Mint System GmbH
    Tel: +41 44 244 7222
    
    
    -- 
    We are hiring: https://www.mint-system.ch/jobs
    Send application to: jobs@mint-system.ch
    
    CTO Mint System GmbH 
    Tel: +41 44 244 7222
    -- 
    We are hiring: https://www.mint-system.ch/jobs
    Send application to: jobs@mint-system.ch
    
    CTO Mint System GmbH 
    Tel: +41 44 244 7222

    _______________________________________________
    Mailing-List: https://odoo-community.org/groups/contributors-15
    Post to: mailto:contributors@odoo-community.org
    Unsubscribe: https://odoo-community.org/groups?unsubscribe

    -- 
    We are hiring: https://www.mint-system.ch/jobs
    Send application to: jobs@mint-system.ch
    
    CTO Mint System GmbH 
    Tel: +41 44 244 7222

    _______________________________________________
    Mailing-List: https://odoo-community.org/groups/contributors-15
    Post to: mailto:contributors@odoo-community.org
    Unsubscribe: https://odoo-community.org/groups?unsubscribe


    by Nils Coenen - 10:32 - 21 Jun 2024
  • Re: Technical Question: Restart Odoo process after res.partner model change
    Hi Pedro,
    
    I did not want to offend anyone and have also tried to do justice to 
    your expertise.
    
    Reading your answer tells me I asked the wrong questions.
    
    Regads,
    
    Janik
    
    On 6/21/24 09:03, Pedro M. Baeza wrote:
    
    > Janik, I'm afraid your deployment process is not correct, not an Odo 
    
    > bug, as both updating or installing changes DB schema, but obviously 
    
    > the Python code should be reloaded for this to happen (aka, the 
    
    > service should be restarted). Questioning an expert like Graeme with a 
    
    > lot of years of experience in such basic things is not a good practice 
    
    > IMO.
    
    >
    
    > Regards.
    
    >
    
    > _______________________________________________
    
    > Mailing-List: https://odoo-community.org/groups/contributors-15
    
    > Post to: mailto:contributors@odoo-community.org
    
    > Unsubscribe: https://odoo-community.org/groups?unsubscribe
    
    >
    
    -- 
    We are hiring: https://www.mint-system.ch/jobs
    Send application to: jobs@mint-system.ch
    
    CTO Mint System GmbH
    Tel: +41 44 244 7222
    
    

    by Janik von Rotz - 09:47 - 21 Jun 2024