mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 02:31:45 +01:00
fix: wait for image upload completion before submitting ad (#716)
## ℹ️ Description Fixes a race condition where ads were submitted before all images finished uploading to the server, causing some images to be missing from published ads. - Link to the related issue(s): Issue #715 - The bot was submitting ads immediately after the last image `send_file()` call completed, only waiting 1-2.5 seconds via `web_sleep()`. This wasn't enough time for server-side image processing, thumbnail generation, and DOM updates to complete, resulting in missing images in published ads. ## 📋 Changes Summary ### Image Upload Verification (Initial Fix) - Added thumbnail verification in `__upload_images()` method to wait for all image thumbnails to appear in the DOM after upload - Added configurable timeout `image_upload` to `TimeoutConfig` (default: 30s, minimum: 5s) - Improved error messages to show expected vs actual image count when upload times out - Added German translations for new log messages and error messages - Regenerated JSON schemas to include new timeout configuration ### Polling Performance & Crash Fix (Follow-up Fix) - Fixed critical bug where `web_find_all()` would raise `TimeoutError` when no thumbnails exist yet, causing immediate crash - Wrapped DOM queries in `try/except TimeoutError` blocks to handle empty results gracefully - Changed polling to use `self._timeout("quick_dom")` (~1s with PR #718) instead of default timeout - Improved polling performance: reduced cycle time from ~2s to ~1.5s - DOM queries are client-side only (no server load from frequent polling) **New configuration option:** ```yaml timeouts: image_upload: 30.0 # Total timeout for image upload and server-side processing quick_dom: 1.0 # Per-poll timeout for thumbnail checks (adjustable via multiplier) ``` The bot now polls the DOM for `ul#j-pictureupload-thumbnails > li.ui-sortable-handle` elements after uploading images, ensuring server-side processing is complete before submitting the ad form. ### ⚙️ Type of Change - [x] 🐞 Bug fix (non-breaking change which fixes an issue) - [ ] ✨ New feature (adds new functionality without breaking existing usage) - [ ] 💥 Breaking change (changes that might break existing user setups, scripts, or configurations) ## ✅ Checklist Before requesting a review, confirm the following: - [x] I have reviewed my changes to ensure they meet the project's standards. - [x] I have tested my changes and ensured that all tests pass (`pdm run test`). - [x] I have formatted the code (`pdm run format`). - [x] I have verified that linting passes (`pdm run lint`). - [x] I have updated documentation where necessary. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Image uploads now verify completion by waiting for all uploaded thumbnails to appear before proceeding. * **Improvements** * Added a configurable image upload timeout (default 30s, minimum 5s). * Improved timeout reporting: when thumbnails don’t appear in time, the app returns clearer feedback showing expected vs. observed counts. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -417,6 +417,13 @@
|
||||
"title": "Publishing Confirmation",
|
||||
"type": "number"
|
||||
},
|
||||
"image_upload": {
|
||||
"default": 30.0,
|
||||
"description": "Timeout for image upload and server-side processing.",
|
||||
"minimum": 5.0,
|
||||
"title": "Image Upload",
|
||||
"type": "number"
|
||||
},
|
||||
"pagination_initial": {
|
||||
"default": 10.0,
|
||||
"description": "Timeout for initial pagination lookup.",
|
||||
|
||||
Reference in New Issue
Block a user