Checklist
Describe the bug
If you pass the relationship variable with incorrect parameters into a CSV file for import, and set continue_on_error: 0, then the record will be saved as valid but without the relationship.
Steps to reproduce the bug
async def test_import_csv_continue_on_error_false(client: AsyncClient) -> None:
class AddressContinueeOnErrorFalseAdmin(ModelView, model=Address):
can_import = True
column_import_list = [Address.id, Address.user]
local_app = Starlette()
local_admin = Admin(app=local_app, engine=engine)
local_admin.add_view(AddressContinueeOnErrorFalseAdmin)
transport = ASGITransport(app=local_app)
async with AsyncClient(
transport=transport,
base_url="http://continue_on_error",
) as local_client:
response = await local_client.post(
"/admin/address/import",
data={"continue_on_error": "no"},
files={
"csvfile": (
"address.csv",
b"id,user\r\n1,adg34gfb13\r\n",
"text/csv",
)
},
)
assert 'Import aborted on invalid row 2. No rows were imported' in response.text
Expected behavior
Stop import and output error.
Actual behavior
Import continues as if nothing happened.
Debugging material
Studying the code led me to these two function calls. It is assumed that the error should have been caught in one of them:
|
merged_import_data, row_errors, row_data = validate_import_row( |
|
foreign_key_errors = await validate_foreign_key_values( |
Here is what comes when you run the test from the example:
print(f'{row = }')
processed += 1
merged_import_data, row_errors, row_data = validate_import_row(
row,
model_view._import_prop_names,
model_view.model,
form_class,
denormalize_wtform_data,
)
print(f'{merged_import_data = }')
foreign_key_errors = await validate_foreign_key_values(
model_view=model_view,
row_data=merged_import_data,
fk_error_cache=fk_error_cache,
)
for field_name, field_errors in foreign_key_errors.items():
row_errors.setdefault(field_name, []).extend(field_errors)
print(f'{row_errors = }')
row = MultiDict([('id', '1'), ('user', 'adg34gfb13')])
merged_import_data = {'id': 1, 'user': None}
row_errors = {}
Environment
sqladmin 0.30.0
Additional context
No response
Checklist
master.Describe the bug
If you pass the
relationshipvariable with incorrect parameters into a CSV file for import, and setcontinue_on_error: 0, then the record will be saved as valid but without the relationship.Steps to reproduce the bug
Expected behavior
Stop import and output error.
Actual behavior
Import continues as if nothing happened.
Debugging material
Studying the code led me to these two function calls. It is assumed that the error should have been caught in one of them:
sqladmin/sqladmin/_import.py
Line 443 in 64372dd
sqladmin/sqladmin/_import.py
Line 451 in 64372dd
Here is what comes when you run the test from the example:
Environment
sqladmin 0.30.0
Additional context
No response