New configuration records reference old ones that have been deleted

Bug #1025797 reported by Don Kirkby on 2012-07-17
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenUpgrade Server
Fix Released
High
Stefan Rijnhart (Opener)

Bug Description

When I try to upgrade from 5.0.16 to 6.0, I get the following error (slightly edited):

IntegrityError: insert or update on table "res_currency_rate" violates foreign key constraint "res_currency_rate_currency_id_fkey"
DETAIL: Key (currency_id)=(12) is not present in table "res_currency".

[...] ERROR:tools.convert.xml_import:Parse error in [...]/server/upgrade-6.0/bin/addons/base/base_data.xml:1215:
<record id="rateIDR1" model="res.currency.rate">
            <field name="rate">14352.00</field>
            <field name="currency_id" ref="IDR"/>
            <field eval="time.strftime('2009-01-01')" name="name"/>
        </record>

Steps to reproduce:
1. Create a new database in 5.0 with no sample data and the manufacturing industry profile.
2. Set the view mode to Extended Interface.
3. Leave the default values for all the other setup steps, and set the chart of accounts to "None".
4. From the Financial Management menu, choose Configuration: Currencies.
5. Delete the record with code "IDR".
6. Run the migration using the options, "--update all --stop-after-init". The error occurs as listed above.

The full command line I use for the migration is as follows:
python openerp-server.py --database migrationtest --update all --stop-after-init --addons ~/upgrade-addons-6.0 --config ~/openerp-server.config

Analysis:
The new import record that you see from base_data.xml references a currency with the XML id "IDR". The import process finds the ir_model_data record that matches and reads a currency id of 12. When it tries to use that id for the insert of res_currency_rate, it violates the foreign key constraint because the original currency was deleted. (Deleting the currency record doesn't delete its matching ir_model_data record in version 5.0.)

During our migration, we found similar problems on other tables: document_directory and product_uom. I'll create separate bugs for them.

Suggested fix:
Recreate any deleted configuration records and mark them as inactive. I'll create a merge proposal with the code.

Related branches

Don Kirkby (donkirkby) on 2012-07-17
description: updated
Changed in openupgrade-server:
status: New → Confirmed
status: Confirmed → Fix Released
importance: Undecided → High
assignee: nobody → Stefan Rijnhart (Therp) (stefan-therp)
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers