mark packages as failed when the state is upload failed#168
Conversation
WalkthroughThis PR adds error handling to detect and mark packages with failed uploads. The changes introduce a workflow that scans MongoDB for failed uploads, retrieves corresponding packages, and marks them as failed in the inventory database. A SQL query bug fix is included. The new error-marking step runs once per iteration in the main watch loop. ChangesUpload Failure Detection and Package Error Marking
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: aaa8dd70-619b-495a-ac89-6dfb34e46a7f
📒 Files selected for processing (3)
data_management/services/dlu_management.pydata_management/services/dlu_mongo.pydata_management/watch_files.py
| package_id = failed_upload["packageId"] | ||
| package = self.dlu_management.get_package(package_id) | ||
| if package is not None: | ||
| if package['dlu_error'] == 1: | ||
| continue | ||
| else: | ||
| self.dlu_management.set_dlu_package_error(failed_upload["packageId"]) | ||
| logger.info("Marked package " + failed_upload["packageId"] + " as error due to UPLOAD_FAILED in MongoDB") |
There was a problem hiding this comment.
Guard missing packageId before dereferencing failed state docs.
At Line 203, direct indexing (failed_upload["packageId"]) can raise KeyError and break this pass if any malformed state document is present. Add a defensive read and skip/log invalid rows.
Proposed fix
def mark_packages_with_error(self):
failed_uploads = self.dlu_mongo.find_by_upload_failed()
for failed_upload in failed_uploads:
- package_id = failed_upload["packageId"]
+ package_id = failed_upload.get("packageId")
+ if not package_id:
+ logger.warning("Skipping UPLOAD_FAILED record without packageId: %s", failed_upload.get("_id"))
+ continue
package = self.dlu_management.get_package(package_id)
if package is not None:
if package['dlu_error'] == 1:
continue
else:
- self.dlu_management.set_dlu_package_error(failed_upload["packageId"])
- logger.info("Marked package " + failed_upload["packageId"] + " as error due to UPLOAD_FAILED in MongoDB")
+ self.dlu_management.set_dlu_package_error(package_id)
+ logger.info("Marked package %s as error due to UPLOAD_FAILED in MongoDB", package_id)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| package_id = failed_upload["packageId"] | |
| package = self.dlu_management.get_package(package_id) | |
| if package is not None: | |
| if package['dlu_error'] == 1: | |
| continue | |
| else: | |
| self.dlu_management.set_dlu_package_error(failed_upload["packageId"]) | |
| logger.info("Marked package " + failed_upload["packageId"] + " as error due to UPLOAD_FAILED in MongoDB") | |
| package_id = failed_upload.get("packageId") | |
| if not package_id: | |
| logger.warning("Skipping UPLOAD_FAILED record without packageId: %s", failed_upload.get("_id")) | |
| continue | |
| package = self.dlu_management.get_package(package_id) | |
| if package is not None: | |
| if package['dlu_error'] == 1: | |
| continue | |
| else: | |
| self.dlu_management.set_dlu_package_error(package_id) | |
| logger.info("Marked package %s as error due to UPLOAD_FAILED in MongoDB", package_id) |
Summary by CodeRabbit
Bug Fixes
New Features