[FIX] base: import record using database identifier
Suppose a user who imports a new picking thanks to this:
```csv
location_id,location_dest_id,picking_type_id
WH/Stock,Partners/Customers,YourCompany: Delivery Orders
```
Then, on the inferface, for one of the fields, he sets the value as
"Database ID" (for instance "Destination Location/Database ID").
When trying to import the file, an error is raised, which could make
sense since the provided value is not a DB identifier, but the error
is actually incorrect:
> Odoo Server Error. Current transaction is aborted, commands ignored
> until end of transaction block
When looking for the destination location in the database, it will
raise a legit error since the domain does not make sense:
`[('id', '=', tentative_id)]`
Hence this:
> ERROR: invalid input syntax for type integer: "Partners/Customers"
The good point is that everything in the code already handles this:
we catch the error and add some detailed explanations in the import
error report, but... The SQL transaction is now broken. So, as soon
as another SQL request is executed, it will trigger an
`InFailedSqlTransaction` error, we will not catch it and this error
will be returned to the frontend (we lose the import report).
sentry-3969379125
closes odoo/odoo#143010
X-original-commit: b0e86e5c6d4b54134b91dbde3a145b551158b76d
Signed-off-by: Rémy Voet (ryv) <ryv@odoo.com>
This commit is contained in:
@@ -432,18 +432,16 @@ class IrFieldsConverter(models.AbstractModel):
|
||||
field_type = _(u"database id")
|
||||
if isinstance(value, str) and not self._str_to_boolean(model, field, value)[0]:
|
||||
return False, field_type, warnings
|
||||
try: tentative_id = int(value)
|
||||
except ValueError: tentative_id = value
|
||||
try:
|
||||
if RelatedModel.search([('id', '=', tentative_id)]):
|
||||
id = tentative_id
|
||||
except psycopg2.DataError:
|
||||
# type error
|
||||
tentative_id = int(value)
|
||||
except ValueError:
|
||||
raise self._format_import_error(
|
||||
ValueError,
|
||||
_(u"Invalid database id '%s' for the field '%%(field)s'"),
|
||||
value,
|
||||
{'moreinfo': action})
|
||||
if RelatedModel.browse(tentative_id).exists():
|
||||
id = tentative_id
|
||||
elif subfield == 'id':
|
||||
field_type = _(u"external id")
|
||||
if not self._str_to_boolean(model, field, value)[0]:
|
||||
|
||||
@@ -706,6 +706,13 @@ class test_m2o(ImporterCase):
|
||||
u"name, external id or database id")])
|
||||
self.assertIs(result['ids'], False)
|
||||
|
||||
def test_fail_id(self):
|
||||
record = self.env['export.integer'].create({'value': 42})
|
||||
result = self.import_(['value/.id'], [["lorem"], [record.id]])
|
||||
self.assertFalse(result['ids'])
|
||||
self.assertTrue(result['messages'])
|
||||
self.assertEqual(result['messages'][0]['message'], "Invalid database id 'lorem' for the field 'Value'")
|
||||
|
||||
def test_name_create_enabled_m2o(self):
|
||||
result = self.import_(['value'], [[101]])
|
||||
self.assertEqual(result['messages'], [message(
|
||||
|
||||
Reference in New Issue
Block a user