From bbc93bc51e32d5bddb22e15b2d3d5013973db0da Mon Sep 17 00:00:00 2001 From: Roland Date: Sat, 3 Oct 2026 10:50:18 -0600 Subject: [PATCH] tests: fix the two suites failing on master test_handle_reorganize_marks_job_failed_on_exception patched wrolpi.files.worker.shutil.move, but #719 moved handle_reorganize and its shutil.move call into wrolpi.files.reorganize_job. test_file_worker_refresh_inserts_new_files loaded FileGroups into the shared pytest session between refreshes. The refresh upserts by raw SQL, so the modeler then read the stale identity-map object and wrote its old file list back over the upsert. Production opens a fresh session per block; expire the test session before the second refresh. Co-Authored-By: Claude Fable 5.1 --- wrolpi/collections/test/test_reorganize.py | 2 +- wrolpi/files/test/test_worker.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/wrolpi/collections/test/test_reorganize.py b/wrolpi/collections/test/test_reorganize.py index 538f27af..bc78954c 100644 --- a/wrolpi/collections/test/test_reorganize.py +++ b/wrolpi/collections/test/test_reorganize.py @@ -238,7 +238,7 @@ async def test_handle_reorganize_marks_job_failed_on_exception( ) file_worker._set_job_status(job_id, 'pending') - with mock.patch('wrolpi.files.worker.shutil.move', side_effect=OSError('disk full')): + with mock.patch('wrolpi.files.reorganize_job.shutil.move', side_effect=OSError('disk full')): await file_worker.handle_reorganize(task) assert file_worker.get_job_status(job_id) == 'failed' diff --git a/wrolpi/files/test/test_worker.py b/wrolpi/files/test/test_worker.py index cfa9690d..b59c1903 100644 --- a/wrolpi/files/test/test_worker.py +++ b/wrolpi/files/test/test_worker.py @@ -835,6 +835,11 @@ async def test_file_worker_refresh_inserts_new_files(async_client, test_session, # Now add a real video file that shares a stem with file1 # (must be a real video file so get_mimetype returns video/mp4) video_file_factory(test_directory / 'docs/file1.mp4') + # Under pytest every get_db_session() is this one shared session. The FileGroups queried + # above would otherwise sit stale in its identity map while the refresh upserts by raw + # SQL, and the modeler would then write that stale file list back over the upsert. + # Production opens a fresh session per block, so only the test needs this. + test_session.expire_all() # Refresh again - should detect the modified FileGroup task = FileTask(FileTaskType.refresh, [test_directory], count=4)