[ORM] psycopg2.ProgrammingError: cannot change number of columns in view

Bug #576779 reported by Nhomar - Vauxoo

This bug report was converted into a question: question #109991: [ORM] psycopg2.ProgrammingError: cannot change number of columns in view.

10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Invalid
Undecided
Unassigned

Bug Description

When you try to modified a postgres view an error appear in the moment you update the module:

Traceback (most recent call last):
  File "./openerp-server.py", line 99, in <module>
    pooler.get_db_and_pool(db, update_module=tools.config['init'] or tools.config['update'])
  File "/home/nhomar/openerp/stable/5.0/instancias/desarrollo/server/bin/pooler.py", line 40, in get_db_and_pool
    addons.load_modules(db, force_demo, status, update_module)
  File "/home/nhomar/openerp/stable/5.0/instancias/desarrollo/server/bin/addons/__init__.py", line 740, in load_modules
    r = load_module_graph(cr, graph, status, report=report)
  File "/home/nhomar/openerp/stable/5.0/instancias/desarrollo/server/bin/addons/__init__.py", line 584, in load_module_graph
    init_module_objects(cr, package.name, modules)
  File "/home/nhomar/openerp/stable/5.0/instancias/desarrollo/server/bin/addons/__init__.py", line 373, in init_module_objects
    obj.init(cr)
  File "/home/nhomar/openerp/stable/5.0/instancias/desarrollo/server/bin/addons/l10n_ve_fiscal_reports/l10n_ve_fiscal_reports.py", line 96, in init
    """)
  File "/home/nhomar/openerp/stable/5.0/instancias/desarrollo/server/bin/sql_db.py", line 77, in wrapper
    return f(self, *args, **kwargs)
  File "/home/nhomar/openerp/stable/5.0/instancias/desarrollo/server/bin/sql_db.py", line 122, in execute
    res = self._obj.execute(query, params)
psycopg2.ProgrammingError: cannot change number of columns in view

For Exampl:

I defined a Class:

class some_sql_view(osv.osv):
    _name = "some.sql.view"
    _description = "View on SQL"
    _auto = False
    _rec_name = 'ai_nro_ctrl'
    _columns = {
        'field1':fields.char('Control No.', size=128, required=False, readonly=True),
        'field2':fields.char('Invoice Number', size=128, required=False, readonly=True),
    }
    def init(self, cr):
        '''
        Create or replace view some_sql_view
        '''
        cr.execute("""
            create or replace view fiscal_reports_purchase as (
                SELECT
                     ai."field1" AS field1,
                     rp."field2" AS field2,
               FORM
                     some_model;
                 )
        """)
some_sql_view()

It works fine i have a view with 2 Fields....
Then I try add an extra field called field3
I add 2 lines......

class some_sql_view(osv.osv):
    _name = "some.sql.view"
    _description = "View on SQL"
    _auto = False
    _rec_name = 'ai_nro_ctrl'
    _columns = {
        'field1':fields.char('Control No.', size=128, required=False, readonly=True),
        'field2':fields.char('Invoice Number', size=128, required=False, readonly=True),
        'field3':fields.char('Invoice Number', size=128, required=False, readonly=True), ################NEW LINE
    }
    def init(self, cr):
        '''
        Create or replace view some_sql_view
        '''
        cr.execute("""
            create or replace view fiscal_reports_purchase as (
                SELECT
                     "field1" AS field1,
                     "field2" AS field2,
                     "field3" AS field3 ################NEW LINE
               FORM
                     some_model;
                 )
        """)
some_sql_view()

In this moment when i apply:

./openerp-server.py -u module -d dbname

This error appear...

I need in tis case conect to postgres and delete mannually the view some_sql_view and try again and it works......

Thanks...

Revision history for this message
Nhomar - Vauxoo (nhomar) wrote :

Correction:

When I said:

    _rec_name = 'ai_nro_ctrl'

Correct is:

    _rec_name = 'field1'

Revision history for this message
Christophe CHAUVET (christophe-chauvet) wrote :

Hi

Add this

import tools.sql import drop_view_if_exists

in your init

drop_view_if_exists('my_view')

Regards,

Changed in openobject-server:
status: New → Won't Fix
status: Won't Fix → Invalid
Revision history for this message
Nhomar - Vauxoo (nhomar) wrote :

Thanks So much!

Only some tag!

when you said:
import tools.sql import drop_view_if_exists
the correct was:
from tools.sql import drop_view_if_exists

and when you said:
drop_view_if_exists('my_view')
the correct was:
drop_view_if_exists(cr, 'my_view')

I add the comment if somebody has this question in future it is available....

Thanks a lot again.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.