After a duplicate Party is deleted, I get "You try to read records that don't exist anymore. (Document type: party.party)"

I replaced a party by another with the wizard. Then when accessing to Invoices, I get the message “You try to read records that don’t exist anymore. (Document type: party.party)” and invoices are blank (no name, no content in list view).
How to repair this?

Did you check the value of the party column in the database? Does it exist in the party_party table? Is there a correct foreign key defined on this column?

Seems correct… I forgot to add that I access to invoices related to the Party. So I think it cannot be the account_invoice.party that’s not correct…
Despite the warning message, I can see each of the six invoices in detailed view. Each time I’m proposed to save the record (though I changed nothing). If I choose Save, I get the error “You can not modify invoice XXX because it is posted, paid or cancelled.”

Was it an error to delete the duplicate Party once replaced by the to-be-kept Party?

I couldn’t solve this. For two Parties that were created twice, I used the Replace wizard to have all existing docs use only one of the duplicated Parties, then I deleted the one without docs. But Invoices attached to the unique remaining Party have a strange behaviour: they cannot be opened, nor displayed, either asking for Save changes (yes answer yields You cannot change posted invoices) or complaining for records non existing.
Any solution to repair this?
Is this a known bug for the Replace party wizard?

This sounds like a field that has no value (or a invalid value) and the client detects this as modified.
This may be a bug on some module that does not set the value for a field that depends on party.

Do you have the steps to reproduce on a fresh database? If so please open a bug.

I couldn’t reproduce it on demo. Seems to be linked to a related field, maybe is it anoter module, as party_relationship or party_history. Examining db by hand showed no missing record in fkeys…
Here is the traceback when reading the invoices:

Traceback (most recent call last):
  File "/Users/jcm/Sites/_tryton/tryton5.0/.env/lib/python3.6/site-packages/trytond/protocols/dispatcher.py", line 176, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "/Users/jcm/Sites/_tryton/tryton5.0/.env/lib/python3.6/site-packages/trytond/model/modelsql.py", line 859, in read
    fields_related[fname])
  File "/Users/jcm/Sites/_tryton/tryton5.0/.env/lib/python3.6/site-packages/trytond/model/modelsql.py", line 830, in read
    getter_results = field.get(ids, cls, field_list, values=result)
  File "/Users/jcm/Sites/_tryton/tryton5.0/.env/lib/python3.6/site-packages/trytond/model/fields/function.py", line 103, in get
    return dict((name, call(name)) for name in names)
  File "/Users/jcm/Sites/_tryton/tryton5.0/.env/lib/python3.6/site-packages/trytond/model/fields/function.py", line 103, in <genexpr>
    return dict((name, call(name)) for name in names)
  File "/Users/jcm/Sites/_tryton/tryton5.0/.env/lib/python3.6/site-packages/trytond/model/fields/function.py", line 98, in call
    return dict((r.id, method(r, name)) for r in records)
  File "/Users/jcm/Sites/_tryton/tryton5.0/.env/lib/python3.6/site-packages/trytond/model/fields/function.py", line 98, in <genexpr>
    return dict((r.id, method(r, name)) for r in records)
  File "/Users/jcm/Sites/_tryton/tryton5.0/.env/lib/python3.6/site-packages/trytond/modules/party/party.py", line 204, in get_rec_name
    if not self.name:
  File "/Users/jcm/Sites/_tryton/tryton5.0/.env/lib/python3.6/site-packages/trytond/model/fields/field.py", line 298, in __get__
    return inst.__getattr__(self.name)
  File "/Users/jcm/Sites/_tryton/tryton5.0/.env/lib/python3.6/site-packages/trytond/model/modelstorage.py", line 1435, in __getattr__
    read_data = self.read(list(ids), list(ffields.keys()))
  File "/Users/jcm/Sites/_tryton/tryton5.0/.env/lib/python3.6/site-packages/trytond/model/modelsql.py", line 759, in read
    cls.raise_user_error('read_error', cls.__name__)
  File "/Users/jcm/Sites/_tryton/tryton5.0/.env/lib/python3.6/site-packages/trytond/error.py", line 74, in raise_user_error
    raise UserError(error)
trytond.exceptions.UserError: Vous essayez de lire des enregistrements qui n'existent plus.
(Type du document: party.party) - 

Do you have an idea of the field I should examine?

From the traceback I see that the problem is reading the name field when computing the rec_name.

As this comes from fields related, it seems that the problem is that invoice is reading the party rec_name of a party that do not exists.

Could you share the steps to reproduce the traceback?

Two identical parties, with invoices on each one. One replaced by another with the Party Replace Wizard. Then the one replaced deleted with the Party Delete Wizard. Show the unique remaining party. Choose Related invoices.

Searching invoices by ID from the client, I noticed that the error occurs only on the invoices that were entered with the now deleted party.

I suspect it is because of the module account_invoice_history. It set the datetime to read the party at the numbered date. But if the replacing party is newer than the numbered date, trying the read for example the rec_name will fail at a date before its creation.
A possible solution would be to update the numbered_at to the creation date of the new party if it is after. Maybe there are other better solutions which allow to keep the real history.

I cannot find numbered_at anywhere in the code. Could you please point me to the place it is defined? Or maybe is it something added after 5.0?

It is defined in account_invoice_history but on 5.0 series it is called open_date.

Thks a sql update solved it.

In party module, when replacing, the replacing could take the create_date value of the replaced maybe.

I filled Issue 9300: Access error for invoice with replaced party - Tryton issue tracker to get a proper solution.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.