Fix: Internal Server Error When Generating Data File for Restored Cases#27
Open
parthdagia05 wants to merge 1 commit intoOSeMOSYS:masterfrom
Open
Fix: Internal Server Error When Generating Data File for Restored Cases#27parthdagia05 wants to merge 1 commit intoOSeMOSYS:masterfrom
parthdagia05 wants to merge 1 commit intoOSeMOSYS:masterfrom
Conversation
…ithout run directory - Ensure res/<caserunname>/ is created before writing data.txt - Add defensive os.makedirs(dataFilePath.parent, exist_ok=True) - Improve route error handling for OSError and unexpected exceptions - Resolves internal server error when restored case metadata exists but run directory was never created
Author
|
can anyone cross check this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug Fix: Defensive Directory Creation for Data Generation 🛡️
Closes: #5
Summary
This PR resolves a 500 Internal Server Error that occurred when attempting to generate a data file for a restored case where the execution directory (
res/<caserunname>/) was missing from the filesystem.This ensures that the application remains resilient even if the metadata exists in
resData.jsonbut the physical directory structure was lost during a backup/restore cycle or manual cleanup.Root Cause Analysis
The
generateDatafile()method attempted to write adata.txtfile directly to the path:res/<caserunname>/data.txtIf the parent directory (
<caserunname>/) did not exist, the operation would raise aFileNotFoundError, crashing the Flask route and returning an unhandled 500 error to the UI.Typical Failure Scenario:
resData.json.Changes Implemented
1. Defensive Directory Provisioning
Added an idempotent directory check using
pathlibbefore the file write operation: