OCA / interface-github

Tools to interact with github from Odoo
GNU Affero General Public License v3.0
46 stars 77 forks source link

[FIX] github_connector: related field not being correctly updated #68

Closed joao-p-marques closed 3 years ago

joao-p-marques commented 3 years ago

After https://github.com/odoo/odoo/commit/82644c3ea20f7b5748f92ce4d0f4585335995d29, a related field is updated through SQL, which raises the need to indicate the appropiate relation that comes from the related table.

The related field image_small has attachment=True, meaning it is not in the res_partner table, causing the following install error:

2021-02-04 10:19:55,955 42 ERROR prod odoo.sql_db: bad query: 
            UPDATE "github_team_partner" AS x
            SET "image_small" = y."image_small"
            FROM "res_partner" AS y
            WHERE x."partner_id" = y.id

ERROR: column y.image_small does not exist
LINE 3:             SET "image_small" = y."image_small"
                                        ^
HINT:  Perhaps you meant to reference the column "x.image_small".

2021-02-04 10:19:55,961 42 WARNING prod odoo.modules.loading: Transient module states were reset 
2021-02-04 10:19:55,962 42 ERROR prod odoo.modules.registry: Failed to load registry 
Traceback (most recent call last):
  File "/opt/odoo/custom/src/odoo/odoo/modules/registry.py", line 86, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/opt/odoo/custom/src/odoo/odoo/modules/loading.py", line 421, in load_modules
    loaded_modules, update_module, models_to_check)
  File "/opt/odoo/custom/src/odoo/odoo/modules/loading.py", line 313, in load_marked_modules
    perform_checks=perform_checks, models_to_check=models_to_check
  File "/opt/odoo/custom/src/odoo/odoo/modules/loading.py", line 195, in load_module_graph
    registry.init_models(cr, model_names, {'module': package.name})
  File "/opt/odoo/custom/src/odoo/odoo/modules/registry.py", line 318, in init_models
    func()
  File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 1020, in update_db_related
    join_field=self.related[0],
  File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 148, in wrapper
    return f(self, *args, **kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 225, in execute
    res = self._obj.execute(query, params)
psycopg2.ProgrammingError: column y.image_small does not exist
LINE 3:             SET "image_small" = y."image_small"
                                        ^
HINT:  Perhaps you meant to reference the column "x.image_small".
2021-02-04 10:19:55,963 42 CRITICAL prod odoo.service.server: Failed to initialize database `prod`. 
Traceback (most recent call last):
  File "/opt/odoo/custom/src/odoo/odoo/service/server.py", line 1162, in preload_registries
    registry = Registry.new(dbname, update_module=update_module)
  File "/opt/odoo/custom/src/odoo/odoo/modules/registry.py", line 86, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/opt/odoo/custom/src/odoo/odoo/modules/loading.py", line 421, in load_modules
    loaded_modules, update_module, models_to_check)
  File "/opt/odoo/custom/src/odoo/odoo/modules/loading.py", line 313, in load_marked_modules
    perform_checks=perform_checks, models_to_check=models_to_check
  File "/opt/odoo/custom/src/odoo/odoo/modules/loading.py", line 195, in load_module_graph
    registry.init_models(cr, model_names, {'module': package.name})
  File "/opt/odoo/custom/src/odoo/odoo/modules/registry.py", line 318, in init_models
    func()
  File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 1020, in update_db_related
    join_field=self.related[0],
  File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 148, in wrapper
    return f(self, *args, **kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 225, in execute
    res = self._obj.execute(query, params)
psycopg2.ProgrammingError: column y.image_small does not exist
LINE 3:             SET "image_small" = y."image_small"
                                        ^
HINT:  Perhaps you meant to reference the column "x.image_small".

Indicating attachment=True also in the related field solves the issue.

@Tecnativa TT28141

ping @victoralmau @pedrobaeza

joao-p-marques commented 3 years ago

make sense, but it is weird that this bug has not been discovered before. (this module is used on OCA instance...)

Yes, I was thinking the same, but the new SQL query will always fail as the column doesn't exist on the related table.

The problem only occurs when installing or updating the module, so maybe that's why the problem hasn't shown up yet...

pedrobaeza commented 3 years ago

This should be fixed in core indeed. @legalsylvain this didn't arise in OCA instance because it's not updated regularly.

pedrobaeza commented 3 years ago

Written a comment on https://github.com/odoo/odoo/pull/65232#issuecomment-773298323

The PR is only 7 days old, so that's why we haven't had the problem till now.

legalsylvain commented 3 years ago

Written a comment on odoo/odoo#65232 (comment)

Thanks @pedrobaeza ! I didn't know that new optimization.

So what is the strategy ? accept this PR or wait for a fix in core ? I'm not sure.

joao-p-marques commented 3 years ago

So what is the strategy ? accept this PR or wait for a fix in core ? I'm not sure

I guess waiting for the core fix would be better. However, this wouldn't harm, I think, and if the fix takes too long, maybe go for this. @pedrobaeza WDYT?

pedrobaeza commented 3 years ago

There's already a PR for fixing it: https://github.com/odoo/odoo/pull/65535, so let's wait a bit, as not sure if this can have another side effect (double attachment).

victoralmau commented 3 years ago

IMO it's not necessary now because odoo solved it.

joao-p-marques commented 3 years ago

Yes, closing this :+1: