Contributors mailing list archives

contributors@odoo-community.org

Browse archives

Avatar

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

by
Mint System GmbH, Janik von Rotz
- 21/06/2024 08:34:40

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

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

_______________________________________________
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

_______________________________________________
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

_______________________________________________
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

Reference