Fix: surface the database error when refreshing a document before moving its files

This commit is contained in:
stumpylog committed 2026-10-30 08:44:57 -07:00
1 parent 3bc1ee5826
commit e5bb3f7dbb
2 files changed
+29 -6

No files matched your search

+23
View File
@@ -2134,3 +2134,26 @@ class TestPathDateLocalization:
with override_settings(FILENAME_FORMAT=filename_format):
filename = generate_filename(document)
assert filename == Path(expected_filename)
@pytest.mark.django_db
def test_refresh_failure_surfaces_database_error(paperless_dirs) -> None:
"""
GIVEN:
- A document with a stored filename
WHEN:
- Saving it triggers a filename update and refreshing it from the database fails
THEN:
- The database error is raised, not an unbound variable error from the rollback
"""
document = DocumentFactory(filename="some.pdf")
with (
mock.patch.object(
Document,
"refresh_from_db",
side_effect=DatabaseError("database is locked"),
),
pytest.raises(DatabaseError, match="database is locked"),
):
document.save()