fix: correct guard order in OsemosysClass.RYE() to prevent phantom 'EmisId' key (#423)#424
Open
tejassinghbhati wants to merge 8 commits intoEAPD-DRB:mainfrom
Open
Conversation
Removed the check for an active session before downloading the CSV.
Removed error handling for inactive session.
Removed session check for active case in download routes.
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.
Linked issue
Existing related work reviewed
Overlap assessment
Why this PR should proceed
Summary
if (year != 'EmisId'):guard before the dict initialisation inOsemosysClass.RYE()(lines 614–618 of API/Classes/Case/OsemosysClass.py)RYE[param][sc]['EmisId'] = {}into the output dict before the guard ran, producing a phantom key that downstream consumers (update_RYE in UpdateCaseClass.py and solver data-file writers) could silently misinterpret as a year valueValidation
Validation command (PowerShell, no case/DB needed):
@"
rye_raw = {'AnnualExogenousEmission': {'SC_0': [{'EmisId': 'CO2', '2020': 0.0, '2021': 0.5}]}}
RYE = {}
for param, obj1 in rye_raw.items():
RYE[param] = {}
for sc, array in obj1.items():
RYE[param][sc] = {}
for o in array:
for year, val in o.items():
if (year != 'EmisId'):
if year not in RYE[param][sc]:
RYE[param][sc][year] = {}
RYE[param][sc][year][o['EmisId']] = val
print('Keys found:', list(RYE['AnnualExogenousEmission']['SC_0'].keys()))
print('Bug fixed:', 'EmisId' not in RYE['AnnualExogenousEmission']['SC_0'])
"@ | python
Expected output:
Keys found: ['2020', '2021']
Bug fixed: True
Documentation
Scope check
Exception rationale
(left blank — this PR has a linked issue)