Skip to content

Fix: Can't regenerate failed/expired ZIMs (#1036)#1059

Merged
audiodude merged 3 commits intoopenzim:mainfrom
ziaddevv:regenerate_failed_zim
Jan 25, 2026
Merged

Fix: Can't regenerate failed/expired ZIMs (#1036)#1059
audiodude merged 3 commits intoopenzim:mainfrom
ziaddevv:regenerate_failed_zim

Conversation

@ziaddevv
Copy link
Contributor

@ziaddevv ziaddevv commented Dec 24, 2025

The bug had some minor issues :

Schedule existence check was using the wrong ID (s_id instead of builder_id) causing the code to think schedules didn't exist when they actually did , This led to 409 Conflict errors when trying to create "new" schedules

after fixing the ID issue , I hit a 405 Method Not Allowed error because the PATCH request was going to /v2/schedules instead of /v2/schedules/{schedule_name} . I have investigated The Zimfarm API requires the schedule name in the URL path

after fixing both API issues the request was made and the ZIM was created but download URLs were still broken because the task_id wasn't being updated properly when selection versions changed, and the version pointer (b_selection_zim_version) still pointed to the old selection

Changes made:

zimfarm.py : Use builder_id instead of s_id for schedule checks, and fix PATCH URL to include schedule name in the path
builder.py: Add three layer update logic (try current selection - - > try by schedule_id --> insert new) and update b_selection_zim_version to point to current selection when requesting ZIMs

I have tested this locally , by reproducing the same issue , it worked fine , i have successfully regenerated the failed ZIMs and verified the download links works fine

I tried to explain the issue well , please review it , maybe I found the causes of the issue , but actually I'm not sure if this is the correct way to solve it
fixes #1036

@audiodude
Copy link
Member

I don't have time to review the code right now, I only read the description. But I wanted to leave immediate feedback to tell you that, based on your description, I really appreciate the problem solving and effort that went into this PR. And I apologize for the state of the code that caused this bug.

I am interested in how the tests passed for this deficient code, but I expect that they were also deficient in the sense that they were testing the incorrect behavior instead of the behavior we actually desired. Please make sure to run and update tests as necessary.

Again, thank you so much! I will review this soon.

Copy link
Member

@audiodude audiodude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic seems sound, so good work. All that's left is to add tests for the 3 new cases (selection version has changed, new zim_task id required, update b_selection_zim_version).

While you're in there, check if the existing tests are even still useful, and be sure to delete or amend as necessary.

Thanks!

@ziaddevv
Copy link
Contributor Author

ziaddevv commented Jan 5, 2026

This logic seems sound, so good work. All that's left is to add tests for the 3 new cases (selection version has changed, new zim_task id required, update b_selection_zim_version).

While you're in there, check if the existing tests are even still useful, and be sure to delete or amend as necessary.

Thanks!

Apologies for the delay on this; I was unavailable last week.

I've added the tests now, and they cover all the cases as requested. I checked the codebase for existing or related tests to reference but couldn't find any, so I implemented these to ensure full coverage of the new logic.

Copy link
Member

@audiodude audiodude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay holidays are over, back to work 😭

This looks good, just needs a few refactors to tests. Thanks!

@ziaddevv
Copy link
Contributor Author

Okay holidays are over, back to work 😭

This looks good, just needs a few refactors to tests. Thanks!

Welcome back, hope you had a great holiday 😊
I’ve refactored the tests as requested . I believe it is way better now
Thanks a lot for your reviews, and let me know if you’d like any further changes.

Copy link
Member

@audiodude audiodude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! The tests look so much better, thanks. I will run the CI and merge now if it passes.

Congratulations on your first WP1 patch! You are officially a WP1/Wikipedia/Kiwix contributor! 🎉

@audiodude audiodude force-pushed the regenerate_failed_zim branch from e3d3473 to a0fc865 Compare January 25, 2026 03:36
@codecov
Copy link

codecov bot commented Jan 25, 2026

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.83%. Comparing base (2bdde2e) to head (a0fc865).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
wp1/logic/builder.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1059      +/-   ##
==========================================
- Coverage   92.84%   92.83%   -0.01%     
==========================================
  Files          74       74              
  Lines        4317     4325       +8     
==========================================
+ Hits         4008     4015       +7     
- Misses        309      310       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@audiodude audiodude merged commit 7c138d7 into openzim:main Jan 25, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't create ZIMs from existing selections with expired/failed ZIMs

2 participants